For in Squirrel
for
is Java’s primary looping construct. Here are some basic types of loops in Java.
The most basic type is a while loop with a single condition. This is equivalent to the for
loop with a single condition in some other languages.
Java also has a classic for
loop with initial condition, termination condition, and increment statement.
To iterate a specific number of times, you can use a for
loop with a range. In Java, this is typically done by iterating from 0 to N-1.
A while(true)
loop in Java will repeat indefinitely until you break
out of the loop or return
from the enclosing method.
You can also use continue
to skip to the next iteration of the loop.
To run the program:
We’ll see some other loop forms later when we look at enhanced for loops, iterators, and other data structures.