Properties of while loop in C Language
Categories: C language
1. A conditional expression is used to check the condition. The statements defined inside the while loop will repeatedly execute until the given condition fails.
2. The condition will be true if it returns 0. The condition will be false if it returns any non-zero number.
3. In while loop, the condition expression is compulsory.
4. Running a while loop without a body is possible.
5. We can have more than one conditional expression in while loop.
6. If the loop body contains only one statement, then the braces are optional.
Example 1
#include<stdio.h>
void main ()
{
int j = 1;
while(j+=2,j<=10)
{
printf("%d ",j);
}
printf("%d",j);
}
Output
3 5 7 9 11
Example 2
#include<stdio.h>
void main ()
{
while()
{
printf("hello Javatpoint");
}
}
Output
compile time error: while loop can't be empty