Loops Flashcards
The three main types of loops in Java.
1) for loop
2) while loop
3) do while loop
A loop situation where we don’t know how many iterations a loop will do in advance.
Indeterminate
Which type of loop is best for indeterminate?
while or do-while
Which type of loop is best for determinate?
for-loop or counter-controlled-while
LCC
Loop Continuation Condition
How do you get an infinite loop?
The loop continuation condition never becomes false
The use of a specific input by the user to end the loop, like zero.
Sentinel Value
Which loop is guaranteed to run at least once?
do-while
Which type of loop is a for-loop? (det/indet)
Determinate
What is it called when you manually adjust a for loop’s counter?
Heretic’s Code
What happens if you put a semicolon at the end of a for-loop header?
Separates the body from the header, making the counter go and then running the body ONCE.
Which keyword is used to exit a loop in the middle of an iteration?
break
Which keyword is used to stop the current iteration of the loop and go back to LCC?
continue
What special loop syntax can be used for traversing data structures?
for:each
What is the syntax of a for:each loop?
for(datatype temp : collection_name)