sometimes we need to execute a block of code in several recurrent times. this action called a loop and for this action Java have some Loop statments as the following:
while Loop:
A while loop is a control structure that allows you to repeat a task a certain number of times. and it means while an expression is true do the action in the block code and do it again and again till the expression result is false.
Syntax:
while(expression) { //Statements }
Example:
public class Test { public static void main(String args[]) { int x = 10; while( x < 20 ) { System.out.print("value of x : " + x ); x++; System.out.print("\n"); } } }
Leave a Reply