Syntax:
initialization
while (condition)
{
statement
Variable increment or decrement operation
}

First, in generic, we initialize the variable, and then we evaluate the condition for the same variable. If it happens to be true, it goes inside the loop, does the job, and then updates the same expression/condition.
Examples:1) Print table of 2
#include<stdio.h> int main() { int i =2; ==> Initialization while ( i < 22) { printf("\n %d", i); i+=2; ==> Incrementation } return 0; }
Note:
If there is a single statement inside the loop or if condition, then we do not need curly( {} ) braces.
Example:
int a =5;
if (a ==5)
print("\n hello world");
Relevant Posts:
Categories: C Language
Leave a Reply