Ticker

6/recent/ticker-posts

Java (While loop)

WHILE LOOP IN JAVA

In the while loop the test condition is check first and then the statements (body part of loop) are executed, if the condition turns out to be true.  
A while loop is never execute, if its test condition would be false.




Example 1: Program To Print Counting 1 - 10

class while_loop
{
public static void main(String  args[])
{
int i=1; // Variable initialization 

while(i <= 10) // Test condition
{
System.out.println(i);
i++;  // Increment statement
}

}

}


- - - PROGRAM OUTPUT - - -


Example 2: Program To Print Reverse Counting 10 - 1


class while_loop
{
public static void main(String  args[])
{
int i=10; // Variable inilization 

while(i >= 1) // Test condition
{
System.out.println(i);
i--;
}

}
}


- - - PROGRAM OUTPUT - - -



















HOME

Post a Comment

0 Comments