while statement in C language | while loop in C language
It is an entry controlled looping statement. It is basically used when we may not be aware of how many times the loop will execute. In while statement, initialization, condition and updation are performed in different lines. The syntax of while statement is:
Initialization;
while(Condition)
{
Statement-Block;
Updation;
}
while is a keyword which specifies that while statement has started.
Initialization is the way to assign some initial value to loop control variable which controls number of times loop should execute.This is the value from where while loop starts.
Example
i=1;
Condition is a relational or logical expression used to check whether the loop should continue or not. The loop will continuously execute as long as condition is true.
Example
i<=10
Updation is to increase or decrease the value of loop control variable.
Example
i++;
If there are more than one updation statements, they should be separated by commas.
Statements refers to C language instructions which are part of while statement.
Program to demonstrate the use of while statement in C Language. |
#include<stdio.h> int main() { int i; i=1; while(i<=5) { printf("\n%d",i); i++; } return(0); } |
Output |
1 2 3 4 5 |
RELATED PROGRAMS
Popular Books of Computer Science