[C #] 7. C # judgment statement

Judgment is mainly used: if statement if ... else ... statement switch statement
Flexible use, if set if switch set switch
 
if statement
if (condition)
{
The conditions are met and executed; // If multiple ifs are used, judgment will be made every time
}
 
if ... else ... statement
if (condition)
{
Executed when the conditions are established;
}
else
{
Executed when the condition is false;
}
 
if...else if()...
if (condition 1)
{
Executed when the conditions are established;
}
else if (condition 2)
{
Executed when condition 2 is established; // If 1 is established, the judgment of 2 is not performed
}
 
switch statement
Allows testing when a variable is equal to multiple values, each value is called a case, and the tested variable will check each switch case
 
switch (variable name) // The defined variable name cannot be a floating point type, and the floating point type cannot be accurately compared due to accuracy issues.
{
case 1: // Label, object of variable comparison
Execute statement 1; //
break;
 
case 2:
Execute statement 2;
break;
}
 
 
 

 

Guess you like

Origin www.cnblogs.com/weigangblog/p/12742988.html