While loop java

Hey guys!! Welcome to flower brackets blog. In this post we are going to learn while loop java.

while loop java

While loop statement run or iterate a block of statements number of times, until condition is true.

Syntax :

while (expression)
{
   // code goes here
}

while loop java

public class WhileLoopDemo 
{
   public static void main(String args[])
   {
      int a = 1;
      while(a < 10)
      {
         System.out.println(a);
         a++;
System.out.print("\n"); } } }

Output :

1
2
3
4
5
6
7
8
9


While loop java : infinite while loop

Now let’s see infinite while loop java with an example,

public class WhileLoopExample 
{
   public static void main(String[] args) 
   {
      boolean value = true;
while(value)
{
System.out.println("Infinite loop");
}
} }

Output:

Infinite loop
Infinite loop
Infinite loop

…….


Also read – if else java

Related Posts