Looping statements
while () Statement: This executes a block of statements as long as a specified condition is true. Syntax : while(condition) { statement(s); } next_statement; The (condition) may be any valid Java expression. The statement(s) may be either a single or a compound (a block) statement. Execution : When program execution reaches a while statement, the following events occur: The (condition) is evaluated. If (condition) evaluates as false the while statement terminates and execution passes to the first statement following statement(s) that is the next_statement. If (condition) evaluates as true the statement(s) iside the loop are executed. Then, the execution returns to step number 1. Example : int i=0; //Initialize loop variable System.out.println("Even numbers\n"); while(i<=10) { System.out.println(i); i+=2; } do..while() Statement do..while loop is used when you need to run some statements and processes once at least before checking t...
Comments