Saturday 4 January 2014

Difference between “while” loop and “do while” loop?

do while: starts executing contents of the loop before looking at the condition. therefore, execution shall run at least for once even if condition doesn't math.

e.g:

int  x=11;
        do{
            System.out.println("human being VS being human");
            x++;
        }while(x<10)
this one will execute 1 time before it goes down to look for the condition, after that it will stop.

and 

while: looks for the condition at the very first before executing the content.

e.g:
int  x=11;
        while(x<10){
            System.out.println("human being VS being human");
            x++;
        };

this one won't go inside the loop since the condition doesn't match.


No comments:

Post a Comment