1 Basic form if (expression) statement
The semantics are: if the expression is true, the subsequent statement is executed, and if the expression is false, the statement is not executed.
Example 1 compares two integers, max is the maximum number.
1 void Main () 2 { 3 int 4 5 max=A; 6 7 if (max<B) 8 { 9 max=b; Ten } one}
2 If ... else form.
if(expression) {statement 1;} Else statement 2;
If the expression is true, execute statement 1, and if it is not true, execute statement 2
Example 2 compares two integers, max of which is the maximum number, and use the If.....else statement to discriminate the size of a/b.
void Main () { int' if(a>b) { =A;} Else { =b;}}
3 switch-case statement.
switch (expression)
{
case constant Expression 1: statement 1;
Case constant Expression 2: statement 2;
Case constant Expression 3: statement 3;
Default: Statement n+1;
}
Evaluates the value of an expression and compares it to the value of the constant expression thereafter, when the value of the expression is equal to the value of a constant expression, that is, executes the subsequent statement, and then ceases to judge, and proceeds to the statement following all the subsequent case;
When the value of an expression is not equal to the constant expression following all of the case, the statement after the default is executed.
Example 4 Switch Statement instance
#include <stdio.h>voidMain0{ Chardat; Day=3; Switch(DAT) { Case 0:p rintf ("sun\t"); Case 1:p rintf ("mon\t"); Case 2:p rintf ("tues\t"); Case 3:p rintf ("wed\t"); Case 4:p rintf ("thurs\t"); Case 5:p rintf ("fri\t"); Case 6:p rintf ("satur\t"); defualt:printf ("This is a worng number\n");}}
The result of the operation is Wed Thurs Fri Satur
Basic Statement of C language