[Study Notes] [C Language] break and continue, breakcontinue

Source: Internet
Author: User

[Study Notes] [C Language] break and continue, breakcontinue

1. Use

Break:
1. application scenarios
1> switch statement: exit the entire switch statement
2> loop structure: exit the entire loop statement
* While
* Do while
*
2. Notes
Valid only for the latest Loop Structure
 
 Continue:
1. application scenarios
Cycle Structure: end the current cycle body and enter the next cycle body
* While
* Do while
*
2. Notes
Valid only for the latest Loop Structure

2. Code

1 # include <stdio. h> 2 3 int main () 4 {5/* 6 for (int I = 0; I <5; I ++) 7 {8 printf ("% d \ n", I); 9 10 if (I % 2) 11 {// I is an odd number: 1, 312 continue; 13} 14} */15/* 16 for (int I = 0; I <5; I ++) 17 {18 19 printf ("HAHAHA \ n "); 20 21 continue; 22 23 printf ("HAHAHA 23 \ n"); 24} */25 26 for (int I = 0; I <3; I ++) 27 {28 for (int j = 0; j <2; j ++) 29 {30 if (j = 1) 31 {32 break; 33} 34 35 printf ("A \ n"); 36} 37 38 break; 39 40 printf ("B \ n"); 41} 42 43 return 0; 44}

3. Summary

1. Select Structure
1. if
1> Structure
If (condition ){

} Else if (condition 2 ){

} Else if (Condition 3 ){

} Else {

}

2> features
* At the same time, only the code in one braces will be executed.

2. switch
1> Structure
Switch (numeric)
{
Case value 1:
Break;

Case value 2:
Break;

Case value 3:
Break;

Default:
Break;
}
2> features
1> by default, only the code after one case is executed.
2> if there is no break after a case, and this case is true, the statements in all subsequent cases will be executed in sequence until the break is encountered.
3> to define a new variable after case, you must wrap it in braces {}.

Ii. Loop Structure
1. while
1> features: if the initial condition is not true, the loop body will never be executed.
2. do while
1> features: the loop body is executed at least once no matter whether the conditions are true or not.
3.
4. Select
1> generally, for loop is preferred.
2> then consider
3> do while

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.