C + + Syntax third flow control syntax

Source: Internet
Author: User

One, branch statements

if ()----else if ()-----Else ():

BOOL b1,b2; if (B1) {      //b1==true Run, jump out after run }Elseif(B2)// can be omitted {      //b1==false,b2==true Run, jump out after run }else/ / can be omitted {     // run when all conditions are not valid }

Switch......case....default

intN;Switch(n) { Case 1:     {           //Run when N==1            Break; }      Case 2:     {           //Run when n==2            Break; }     default      //can be omitted     {           //run when no match is found     }}

Second, the Loop statement

while ()

BOOL b;  while (b) {       /        /loop body // when B==true enters the loop body, otherwise does not enter the loop body }

for ()

int i,n;n=ten;  for (i=0; i<n;i++) {       // loop N-Times }

C + + Syntax third flow control syntax

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.