With a break statement forces the end of the cycle

Program code using the multiplication table 2 cyclic display example:

#include<stdio.h>

int main()
{
    
    int i,j;
    
    for( i = 1;i<=9;i++){
        for(j = 1;j<=9;j++)
            printf("%3d",i*j);
            putchar('\n');        //换行 
    } 
        
    return 0; 
    
}

If you want the program displays the value of 40 or less, can be inserted break:

for( i = 1;i<=9;i++){
        for(j = 1;j<=9;j++){
            int seki = i*j;
            if(seki >40)
                break; 
            printf("%3d",seki);
        }
            putchar('\n');        //换行 
    } 

  After the break before we have learned to perform in a switch statement, the program will jump out of the switch statement. The break statement after the execution loop, the program will be out of the loop.

  However, when performing multiple loops in a break statement, only the inner loop will jump (where j is a control variable for statement), but also will not suddenly jump out outside the loop (i.e., a control variable i for statement).

  In this procedure, when a product of i and j is more than 40, break out of a program statement will cause the inner loop for statement.

Guess you like

Origin www.cnblogs.com/zhaoyunt/p/11442864.html