while statement in c language
While statement is an entry controlled iterative statement. The syntax of while statement is:
while is a keyword to start while statement.
Initialize: In this part, we assign some value to the control variable which controls number of times the loop should execute.
Update: Increasing or decreasing the value of control variable comes under this part.
Statements are set of instructions which will repeatedly execute as long as condition evaluates to true.
Description of Program
Initially variable counter is assigned value 1.
Value of counter is tested against 5. If value of counter is less than five, printf(“\n%d”,counter) gets executed.
After this statement, update statement counter++ increments value of counter by 1 to make it 2.
Condition counter<=5 is tested again. If condition is true, printf(“\n%d”,i) is executed again.
Update statement will work again.
This process repeats as long as condition remains true.
Best Books of Computer Science