[Solved] For loop misunderstanding in java


A for loop is a control statement, but you still need some operations for that statement to exercise.

The format is

for (some expression controlling the number of times to do something) {
   some commands to run.
}

Currently your for loop lacks the block of commands to run

In addition, the format of the controlling expression is typically shown in three parts

for (run this first; check this each time before running the block; run this after each run of the block) {
   ... commands ...
}

Note that the semicolons are not optional but the actual items within each place separated by the semicolons are

A typical for loop might look like

for (int i = 0; i < 10; i++) {
   System.out.println("number " + i);
}

Where before the loop is run, the variable i is set to zero.
Before each execution of System.out.println("number " + i); it is verified that i < 10 evaluates to true.
After each time System.out.println("number " + i); is executed, the variable i is incremented through the operation i++.

solved For loop misunderstanding in java