Iteratation Flashcards
While loop
While (condition) {
Statements;
}
Will always run until condition is false
Do-while
Loop to be ran prior to condition check and will go back to the top
Do {
Statements;
} while (condition);
For loop
Runs for a set number of iterations
For (initialisation; condition; Increase/decrease) {
}
Initialise: initialise the variable used for condition
Condition: checks If loop should be executed or not
Increase/decrease: affects variable to check the condition
For (int counter =1; counter <= 10; counter++) {
}
Nested loops
Loop inside loop
Break statement
Terminates a loop and code goes back to normal flow, can also be used for switches
EXITS LOOP
Continue statement
Skips current iteration and continues to next iteration
I .e if we skip 3 of an iteration we go to irritation number 4
When does iteration occur in code?
After statements have occurred.
So read initialisation see if it meets condition, perform statements then iteration