While loop
-is a statement or block of statements that is repeated as long as some condition is satisfied.
while loop has the form:
while( boolean_expression )
{
statement1;
statement2; . . .
}
-The statements inside the while loop are executed as long as the boolean_expression evaluates to true.
Example 1
int x = 0;
while (x<10) { System.out.println(x); x++; }
Example 2
//infinite loop
while(true)
System.out.println(“hello”);
Example 3
//no loops
// statement is not even executed
while (false)
System.out.println(“hello”);
Thursday, March 12, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment