for


The for statement is used to run the same line or code block continuously as long as a condition is true. Be careful to make sure that your condition will eventually be false, or the loop will not end. Syntax:

for(starting assignment; condition; incrementation)
{
    // code block
}

starting assignment: This first part is usually used to assign a counting variable to zero at the beginning of the loop. JK performs this assignment before testing the condition, and does not run it again afterwards.

condition: Before JK runs the code, it checks this condition. If the condition is true, JK goes on to run the code; if false, JK ends the loop.

incrementation: After the block of code is run, JK performs another variable assignment. This is usually the incrementation of the counting variable.


Here's a working example of a for loop:

for(i=0; i < 5; i=i+1) PrintInt(i);