C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Point Out Errors (Q.No. 4)
4.
Point out the error, if any in the while loop.
#include<stdio.h>
int main()
{
    int i=1;
    while()
    {
        printf("%d\n", i++);
        if(i>10)
           break;
    }
    return 0;
}
There should be a condition in the while loop
There should be at least a semicolon in the while
The while loop should be replaced with for loop.
No error
Answer: Option
Explanation:

The while() loop must have conditional expression or it shows "Expression syntax" error.

Example: while(i > 10){ ... }

Discussion:
2 comments Page 1 of 1.

Sourav said:   8 years ago
I think D is the correct answer.
(1)

Jack said:   8 years ago
Why does a while loop requires condition whereas for loop doesn't?

Ex: for(;;)
{
printf("%d\n", i++);
if(i>10)
break;
}

Please anyone help me.

Post your comments here:

Your comments will be displayed after verification.