do while loop c code example

Example 1: do whie loop

do{
----
} while(condition);

Example 2: c do while

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

Example 3: WHILE loop in c

while( a < 20 ) {
      printf("value of a: %d\n", a);
      a++;
   }

Example 4: while loop in c

//While loop, for the largest of two numbers.
#include <stdio.h>
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 5: do-while in c

#include <stdio.h>
int main()
{
	int j=0;
	do
	{
		printf("Value of variable j is: %d\n", j);
		j++;
	}while (j<=3);
	return 0;
}

Example 6: c make loop

// Print numbers from 1 to 5

#include <stdio.h>
int main()
{
    int i = 1;
    
    while (i <= 5)
    {
        printf("%d\n", i);
        ++i;
    }

    return 0;
}