The While Loop
by
, January 29th, 2012 at 04:46 PM (1164 Views)
The While Loop is an excellent way of outputting data until reaching a specific point. It's used by running instructions until a condition is no longer true. Basically, it's going to keep running the same set of instructions until the specified condition is modified so as to be false, to reiterate. Sometimes, While Loops can create infinite loops. Usually, While Loops have an instruction at the end of the instruction set which modifies (usually increments) a counter variable being used in the condition so as to bring the condition closer to being false.
Single Line While Loop
while(condition) instructions if condition proves true...
Multiple Line While Loop
while(condition){ instructions if condition proves true... instructions if condition proves true... }
Java Example
while(age<13){ System.out.println("You are "+age+" years old. You are not yet a teenager!"); age++; }