Lesson 4: Repetition Control Structure Flashcards
are used to execute a block of code
repeatedly based on a given condition or set of conditions
Looping statements
These
statements are fundamental to Java programming, allowing for
iteration over data structures, repetitive tasks, and more
Looping statements
4 types of looping statements in Java
- For loop
- While loop
- Do-while loop
- Nested loop
is a control structure that allows repeated execution of
a block of code for a specific number of times
for loop
It is typically used when the
number of iterations is known beforehand
for loop
is executed (one time) before the
execution of the code block
Initialization
defines the condition for executing the code block
Condition
is executed (every time) after the code block has been executed
Update
repeatedly executes a block of code as
long as a specified condition remains true
while loop
It is ideal for
situations where the number of iterations is not
predetermined
while loop
The loop continues to run as long as this condition evaluates
to true
Condition
The statements inside the loop execute repeatedly until the condition becomes false
Code block
is a post-tested loop, meaning it executes the
body of the loop at least once before checking the condition
do-while loop in Java
This loop is
useful when you need to ensure that the loop body is executed at least
once, regardless of whether the condition is true or false
do-while loop
Do-while loop process repeats until the condition
becomes ____
false
This keyword starts the do-while loop
do
These are the actions you want to perform. This block of code is executed on each iteration of the loop, and it is guaranteed to run at least once
Statements to execute
This keyword is followed by a condition in parentheses
while
A Boolean expression that is evaluated after the loop body has executed. If this condition
evaluates to true, the loop will execute again. If it evaluates to false, the loop will terminate, and control
passes to the statement immediately following the loop.
Condition
It is also possible to place a loop inside another loop. This is called a ________
nested loop
The “________” will be executed one time for each iteration of the
“________”:
inner loop; outer loop