What are the differences between a while loop and a for loop?
While Loop: Condition checked before each iteration, more flexible. | For Loop: Initialization, condition, and increment in one line, preferred when iterations are known.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Flip
Revise later
SpaceTo flip
If confident
All Flashcards
What are the differences between a while loop and a for loop?
While Loop: Condition checked before each iteration, more flexible. | For Loop: Initialization, condition, and increment in one line, preferred when iterations are known.
What are the differences between charAt() and substring()?
charAt(): Returns a single character at a specified index. | substring(): Returns a new string that is a substring of this string.
What are the steps to reverse a string using a loop?
1. Initialize an empty string. 2. Iterate through the original string from the last character to the first. 3. Append each character to the new string.
What are the general steps for using a `while` loop?
1. Initialize a counter variable. 2. Write the `while` loop condition. 3. Include the code to be executed within the loop. 4. Update the counter variable inside the loop.
What are the general steps for using a `for` loop?
1. Initialize the loop variable in the for loop declaration. 2. Define the loop condition. 3. Specify the increment/decrement operation. 4. Include the code to be executed within the loop.
What are the steps to trace a loop?
1. Create a table with variables. 2. Execute each line of code. 3. Update the table with the new values. 4. Check the loop condition.
What are the steps to find a specific substring?
1. Iterate through the string. 2. Extract a substring of the same length as the target substring. 3. Compare the extracted substring with the target substring. 4. If they are equal, return true; otherwise, continue.
What is iteration?
Repeating a block of code.
What is a while loop?
A loop that executes while a condition is true.
What is a for loop?
A loop with initialization, condition, and iteration in one line.
What is a nested loop?
A loop inside another loop.
What is string traversal?
Processing a string character by character.
What is tracing?
Manually executing code step-by-step.
What is an infinite loop?
A loop that never terminates.
What is the body of a loop?
The code that is executed repeatedly.
What is a loop condition?
The boolean expression that determines if a loop continues.