Zoo tutorials: [ SQL | Linux | XML ]
ProgZoo: [ Java | C# | VB | C++ | Perl ]
Log in

A Gentle Introduction to
Java Programming

while

 

Control Structures

while

The while statement keeps executing the statement while the condition holds true.

1. [ Java ] while


Big

We test the string read in against the value "Ajax". While the string is different the loop keeps going.

2. [ Java ] while .. break


Big

This version does the same as above but is slightly safer.

The loop quits when the target value "Ajax" is found. If the target value does not show up the loop will quit without an exception.

3. [ Java ] while .. continue


Big

The continue statement short cuts the execution of the body. The next iteration starts right away. This is useful for skipping values.

Here we skip all values that do not have exactly 4 characters.