0

Can somebody help in explaining "While loop"??

30th Mar 2019, 4:44 PM
Riya Sagar
Riya Sagar - avatar
3 Réponses
+ 2
It will keep loop as long the condition is true. // This is an infinite loop this wont stop loop until you do it. while(true){ System.out.println("a loop"); } // Another example int num = 1; while(num <= 5){ System.out.println(num); num++; // for each loop we add 1 } // The above example will keep loop until num is less or equals 5
30th Mar 2019, 5:23 PM
JavaBobbo
JavaBobbo - avatar
+ 1
The while statement is called a loop structure because it executes statements repeatedly while an expression is true, looping over and over again. The expression evaluates to either true or false, and statements can be a single statement or, more commonly, a code block enclosed by curly braces { }. The while loop evaluates a condition before the loop is entered, making it possible that the while statements never execute. The break statement is useful for immediately exiting a loop. When you want to remain in the loop, but skip ahead to the next iteration, you use the continue statement.
30th Mar 2019, 7:25 PM
Luka
0
Thanku
30th Mar 2019, 5:46 PM
Riya Sagar
Riya Sagar - avatar