Well let me explain what a for loop is.
A for loop is much like a while loop. In fact a for loop can be used as a while loop given a certain scenario, but we will get to that later.
All for loops have the following format
for( initial_condition ; boolean_expression ; ending_expression)
// body
So, we have an initial condition, where you can initialize a variable if you'd like.
Then a boolean expression that tests a condition if it's true or false. If it's true then it goes into the body of the loop.
At the end of the body the ending_expression is then called in the for loop, and we evaluate the boolean expression all over again.
So for example, if I wanted to count to ten from 1
for(int i = 1; i <= 10; i++)
{
System.out.println(i);
}
output:
We have an initial condition where we initalize i to 1; (int i = 0)
We have a boolean test (i <= 10)
And we have an ending condition to increment the number i (i++)
An equivalent while loop:
int i = 1;
while(i <= 10)
{
System.out.println(i)
i++;
}
Greetings
Marcus