Alex Rivera | Logout

Difference between "while" loop and "do while" loop

Asked 2010-09-02T09:27:01.383
42

What is the difference between while loop and do while loop. I used to think both are completely same.Then I came across following piece of code:

do {
        printf("Word length... ");
        scanf("%d", &wdlen);
    } while(wdlen<2);

This code works perfectly. It prints word length and tascans the input. But when I changed it to

while(wdlen<2){
        printf("Word length... ");
        scanf("%d", &wdlen);
    } 

It gives a blank screen. It do not work. So there is some functional difference between both loops. Can anybody explain it?

Is there any other difference in these two?

Edit
Report

1 Answer

3

do while in an exit control loop. while is an entry control loop.

answered 2013-03-19T04:29:39.680

Your Answer