Rohan G CollegeBoard Unit 4 For Loops
Week 9 Unit 4 Lesson
for (initialize; test condition; change)
{
loop body
}
for (int x = 1; x <= 5; x++) {
System.out.println(x);
}
Control Flow Diagram
- The code in the initialization area is executed only one time before the loop begins
- the test condition is checked each time through the loop and the loop continues as long as the condition is true
- the loop control variable change is done at the end of each execution of the body of the loop
- When the loop condition is false, execution will continue at the next statement after the body of the loop.
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
for (int i = 0; i < cars.length; i++) {
System.out.println(cars[i]);
}