27 Jump control statements continue

1, continue statement is used to end this cycle, the next cycle continues

2, continue statement, only with the use of loops, not individually and switch / if used

3, Exercise 1:

  The number of positive and negative numbers into an integer number of indeterminate read from the keyboard, and determines whether the read-in program ends when the input is 0

  for loop, break, continue to complete.

. 1 #include <stdio.h>
 2  
. 3  void main () {
 . 4      int positive = 0 ;   // save positive number 
. 5      int negative = 0 ;   // save negative number 
. 6      int NUM = 0 ;   // input digital preservation 
. 7      for (;;) {// is an infinite loop
 . 8          the printf ( " Please enter an integer: " );
 . 9          Scanf ( " % D " , & NUM);
 10          IF (NUM == 0 ) {
. 11              the printf ( " exit loop \ n- " );
 12 is              BREAK ;
 13 is          }
 14          IF (NUM> 0 ) {
 15              positive ++ ;
 16              Continue ;
 . 17          }
 18 is          negative ++ ;
 . 19      }
 20 is      the printf ( " Enter% d positive number,% d a negative " , positive, negative);
 21 is }

 

 4, Exercise 2:

  There 10,0000 yuan a person, not through a crossing, payment of fees, rules are as follows:

  When the cash> 50000, each pay 5%;

  When the cash <= 50000, each post 1000

  Calculate how many times that person can go through the intersection, complete use while break

. 1  void main () {
 2      int Money = 100000 ; // save money 
. 3      int COUNT = 0 ; // COUNT by several statistics intersection 
. 4      the while ( . 1 )    // infinite loop
 5          // determining whether the exit 
. 6          IF (Money < 1000 ) {
 . 7              the printf ( " through junctions% d,% d remaining element, exits the loop " , COUNT, Money);
 . 8              BREAK ;
 . 9          }
 10          IF (Money> 50000 ) {
. 11              Money * = 0.95 ;
 12 is          }
 13 is          the else {
 14              Money - = 1000 ;
 15          }
 16          COUNT ++;   // through a junction plus 
17      }
 18 is  
. 19 }

 

Guess you like

Origin www.cnblogs.com/shanlu0000/p/12347758.html