while loops c code example

Example 1: c do while

do {
    // code
} while(/* condition */);

Example 2: while loop in c

//While loop, for the largest of two numbers.
#include 
int main(){
	int a, b;
    printf("Enter Values a and b:\n");
    scanf("%d %d", &a, &b);
    while (a < b){
    	printf("%d is greater than %d\n", b, a);
      	printf("Enter Values a and b:\n");
      	scanf("%d %d", &a, &b);
    }
    	printf("%d is greater than %d\n", a, b);
      
}

Example 3: whiel loop in C

while (testExpression) 
{
    // statements inside the body of the loop 
}

Tags:

Misc Example