for loop

Know how to write a for loop.

Understand what each part of the for loop does.

Know how to use the for loop variable inside the loop.

Know how to nest a for loop inside another for loop.

There are 3 parts of a for loop separated by semi-colons. Here is an example:
for ( int i = 0; i < 10; i++){
}
In the above example:

int i = 0 ;      is an example of code executed once, before the loop starts. It is often used to initialize a counter with a value of zero. In this example the counter is called i but it can be any legal variable name.

i < 10 ;     is an example of a boolean condition ( just like the ones used in if statements). The loop will continue to repeat as long as this condition is true

i++      is an example of code that is executed at the end of the loop every time the loop repeats. In the example, it is adding one to the counter.

Here is another example of a for loop:
for ( int i = 10; i > 0; i-=2){
}
In this example, the start code sets the counter to 10, then subtracts 2 each time the loop repeats until it reaches 0.
Notice that the condition is i greater than 0 ( i > 0 ) because the counter is now counting down.

You can put a for loop inside another for loop (this is called nesting), but they usually use different variables like this:
for ( int i = 10; i > 0; i-- ){
    for ( int j = 0; j < 10; j++ ) {
        System.out.println("Loop");
    }
}
In the above example, the inside loop will repeat 10 times for every one execution of the outside loop. This will result in "Loop" being printed 100 times.