Ticker

6/recent/ticker-posts

Java (Do while loop)

DO WHILE LOOP IN JAVA





INTRODUCTION
In the Do while loop, statements (loop's body part instructions) executes first then, it will check the test condition and if the condition turns out to be true then the statements are executed again.


A do while loop runs at least once even though the test condition given is false.


int a=1;
do
{
System.out.println(a);
a=a+1;
}

while(a >10);

----------------------------
         OUTPUT 
----------------------------
1

Program Explanation: The above program will print only 1, because the do-while loop execute at-least once, even it test condition would be false.


PROGRAM TO PRINT REVERSE COUNTING 10-1 BY DO WHILE LOOP
class do_while
{
public static void main(String args[])
{
int i=10;

do
{
System.out.println(i);
i--;
}

while(i >= 1);
}
}


- - - PROGRAM OUTPUT - - -







FOR LOOP IN JAVA >>












HOME

Post a Comment

0 Comments