Aqua Phoenix
     >>  Lectures >>  Java 1  
 

Navigator
   
 
       
   

1.15 Loops

The Java syntax for loops is very similar to the one in C:

1.15.1 For Loops

int i;
for (i = 0; i < 10; i++) {
  ...
}
The loop variable can be initialized within the for-loop statement:

for (int i = 0; i < 10; i++) {
  ...
}
An infinite for-loop, again, is similar to the one in C:

for (;;) {
  ...
}

1.15.2 While Loops

boolean cont = true;
while (cont) [
  ...
}
or:

while (i > 0) {
  ...
}