Do While Example


#include <stdio.h>
int main () {
int i = 0;
int loop_count = 5;

printf("Case1:\n");
do {
printf("%d\n",i);
i++;
} while (i<loop_count);

printf("Case2:\n");
i=20;
do {
printf("%d\n",i);
i++;
} while (0);

printf("Case3:\n");
i=0;
do {
printf("%d\n",i);
} while (i++<5);

printf("Case4:\n");
i=3;
do {
printf("%d\n",i);
i++;
} while (i < 5 && i >=2);
return 0;
}
 
Case1:
 0
 1
 2
 3
 4
 Case2:
 20
 Case3:
 0
 1
 2
 3
 4
 5
 Case4:
 3
 4
# 

3 comments:

  1. #include
    int main()
    {
    int n = 0 ;
    while(n <= 4)
    {
    printf("%d\n", n);
    n++;
    }
    return 0;
    }
    sir...
    some problem case-1..2..3 divide is not execute


    ReplyDelete
  2. //Write a program to illustrate the use of Do-While Loop


    #include
    int main ()

    {

    int i = 0,cnt=10;

    printf("\nLoop-1:\n");
    do
    {
    printf("%d ",i);
    }
    while (i++<=cnt);

    printf("\n\nLoop-2:\n");
    i=20;
    do
    {
    printf("%d ",i);
    i++;
    }
    while (0);

    printf("\n\nLoop-3:\n");
    i=0;
    do
    {
    printf("%d ",i);
    }
    while (i++<5);

    printf("\n\nLoop-4:\n");
    i=3;
    do
    {
    printf("%d ",i);
    i++;
    }
    while (i < 10 && i >=2);
    return 0;
    }

    ReplyDelete

  3. main ()
    {
    int i = 0, loop_count = 5;
    printf("Case1:\n");
    do
    {
    printf("%d\n",i++);

    }
    while (i<=loop_count);

    printf("Case2:\n");
    i=15;
    do
    {
    printf("%d\n",i++);

    }
    while (0);

    printf("Case3:\n");
    i=2;
    do
    {
    printf("%d\n",i++);

    }
    while (i++<=5);

    printf("Case4:\n");
    i=3;
    do
    {
    printf("%d\n",i++);

    }
    while (i++ <= 5 && i++ <=2);
    return 0;
    }




    ReplyDelete