Six branch statement

if statement analysis

if statement is used to select the execution statement according to the condition

else cannot stand alone and always matches its nearest if

You can connect other if statements after the else statement

 

if(condition)

{

// statement 1

}

else

{

//  statement 2

}

Points to note about zero value comparison in if statements

bool variables should appear directly in the condition, do not compare

When comparing a variable with a value of 0, the value of 0 should appear to the left of the comparison symbol

float type variables cannot be directly compared with 0 value, you need to define the precision

bool b = TRUE;

if (b)

{

// statement1

}

else

{

// statement 2

}

 

int  i = 0;

if (0 == i)

{

// statement 1

}

else

{

// statement 2

}

#define EPSION 0.000001

float f = 0.0;

if ((-EPSION  <= f) && (f <=-EPSION ))

{

// statement 1

}

else

{

// statement 2

}

swith statement analysis

The switch statement corresponds to a single condition with multiple branches

The case statement branch must have a break, otherwise it will cause branch overlap

The default statement is necessary to deal with special cases

switch(expression)

{

case CONST_1:

// code block

break;

case CONST_2:

// code block

break;

default:

  // code block

}

The value in the case statement can only be integer or character

order of case statements

   Arrange the sentences in alphabetical or numerical order

   Put the normal situation in the front, and the abnormal situation in the back

   The default statement is only used to deal with the real default situation

 

 

Wow
Published 206 original articles · praised 18 · 70,000 views

Guess you like

Origin blog.csdn.net/lvmengzou/article/details/104397795
Recommended