Write a Program in C That Using The Break Statement In a For Statement

// Using the break statement in a for statement
#include <stdio.h>

// function main begins program execution
int main( void )
{
   int x; // counter
   
   // loop 10 times
   for ( x = 1; x <= 10; ++x ) {

      // if x is 5, terminate loop
      if ( x == 5 ) {
         break; // break loop only if x is 5
      } // end if

      printf( "%d ", x ); // display value of x
   } // end for
   
   printf( "\nBroke out of loop at x == %d\n", x );
} // end function main

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...