Advertisement
paulogp

break and continue

Jul 25th, 2011
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. // apple xcode
  2. // paulogp
  3.  
  4. /* break and continue */
  5. /* like the break keyword, the continue keyword is used to affect
  6.  how a loop loops. this time, the job is to immediately repeat the
  7.  loop, skipping over the remaining statements and starting the loop
  8.  over with the first line (the for, while, or do or whatever started
  9.  the loop in the first place) */
  10.  
  11. #include <stdio.h>
  12.  
  13. int main (int argc, const char * argv[])
  14. {
  15.     int the_n = 0;
  16.    
  17.     for (;;) // infinite loop
  18.     {
  19.         the_n++;
  20.        
  21.         if (the_n <= 5)
  22.         {
  23.             printf("%d, ", the_n);
  24.             continue;
  25.         }
  26.        
  27.         printf("%d e maior que 5!\n", the_n);
  28.         break;
  29.     }
  30.    
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement