From Progzoo
Jump to navigation Jump to search

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


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

[Font] [Default] [Show] [Resize] [History] [Profile]

while .. break

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.

[Font] [Default] [Show] [Resize] [History] [Profile]

while .. continue

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.

[Font] [Default] [Show] [Resize] [History] [Profile]