|Top Previous Next|
Executes statements as long as the Boolean condition evaluates to true.
for ([initializer]; [condition]; [iterator])
If initializer is present, variables are initialized or expression statements are executed once. If present, condition is evaluated and if true, the expressions of the iterator, if any, are evaluated in sequence, and then another iteration are evaluated and another iteration is performed. If the condition is false or missing, control is transferred to the end of the for statement.
A break statement can be used within the for statement to transfer control to the end of the for statement, ending iteration of the statement. A continue statement can be used within the for statement to transfer control to the end of the for statement, executing iterator and performing another iteration.
var limit = 100;
Net.write("Prime numbers between 1 and " + limit + ": ");
for(i=1; i < 100; i++)
var isPrime = true;
for(j=2; j < i ; j++)
if(i % j == 0)
isPrime = false;
Net.write(i + " "); // Returns Prime numbers between 1 and 100: 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97