Interview Questions   Tutorials   Discussions   Programs   

C - Program for while and do while?




457
views
asked marvit May 21, 2014 04:34 AM  

Program for while and do while?


           

1 Answer



 
answered By Joseph   1  

#include <stdio.h>

int main()
{
  int x;
  /* The loop goes while x < 10, and x increases by one every loop*/
  for ( x = 0; x < 10; x++ ) {
    /* Keep in mind that the loop condition checks
      the conditional statement before it loops again.
      consequently, when x equals 10 the loop breaks.
      x is updated before the condition is checked. */  
    printf( "%d\n", x );
  }
  getchar();
}






#include <stdio.h>

int main()
{
 int x = 0; /* Don't forget to declare variables */
 
 while ( x < 10 ) { /* While x is less than 10 */
   printf( "%d\n", x );
   x++;       /* Update x so the condition can be met eventually */
 }
 getchar();
}

flag   
Still need some modifications
flag
Apr 19, 2015 12:05 AM
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert