C MCQ set number 00726

In do-while loop, condition is always tested after the the execution of the iteration and if condition fails, loop terminates. Therefore, do-while loop executes at least one iteration before termination if condition fails in first iteration! For example:

#include <stdio.h>
 
int main(void)
{
    int counter = 0;
 
    do {
        /* loop executes just once printing the value 0 */
 
        printf("counter is %dn", counter);
    } while(counter++ != 0);
 
    return 0;
}

In while loop, condition is checked before execution of each iteration and as condition fails, loop terminates. For example:

#include <stdio.h>
 
int main(void)
{		
    int counter = 0;
 
    /* loop terminates in the beginning of first iteration */
 
    while (counter++ != 0)
        printf("counter is %dn", counter);
 
    /* here counter val is printed as 1 */
 
    printf("counter is %dn", counter);
    return 0;      
}
ed010d383e1f191bdb025d5985cc03fc?s=120&d=mm&r=g

DistPub Team

Distance Publisher (DistPub.com) provide project writing help from year 2007 and provide writing and editing help to hundreds student every year.