分支语句(Branch statement)

流程控制

流程控制语句的分类

  • 顺序结构
  • 分支结构(if,switch)
  • 循环结构(for,while,do…while)

顺序结构

顺序结构是程序中最简单最基本的流程控制,没有特定的语法结构,按照代码的先后顺序,依次执行,程序中大多数的代码都是这样执行的。

顺序结构是程序中最简单最基本的流程控制,没有特定的语法结构,按照代码的先后顺序,依次执行,程序中大多数的代码都是这样执行的。

if语句

if语句格式1:

if (关系表达式) {
语句体;
}

if (关系表达式) {

语句体;

}

if语句格式2:

if (关系表达式) {
语句体1;
} else {
语句体2;
}

if (关系表达式) {

语句体1;

} else {

语句体2;

}

if语句格式3:

if (关系表达式1) {
语句体1;
} else if (关系表达式2) {
语句体2;
}
……
else {
语句体n+1·;
}

if (关系表达式1) {

语句体1;

} else if (关系表达式2) {

语句体2;

}

……

else {

语句体n+1·;

}

————————

Process control

Classification of process control statements

  • Sequential structure
  • 分支结构(if,switch)
  • 循环结构(for,while,do…while)

Sequential structure

Sequential structure is the simplest and most basic process control in the program. There is no specific syntax structure. It is executed in sequence according to the sequence of codes. Most codes in the program are executed in this way.

Sequential structure is the simplest and most basic process control in the program. There is no specific syntax structure. It is executed in sequence according to the sequence of codes. Most codes in the program are executed in this way.

If statement

If statement format 1:

If (relational expression){
Statement body;
}

If (relational expression){

Statement body;

}

If statement format 2:

If (relational expression){
Statement body 1;
} else {
Statement body 2;
}

If (relational expression){

Statement body 1;

} else {

Statement body 2;

}

If statement format 3:

If (relational expression 1){
Statement body 1;
}Else if (relational expression 2){
Statement body 2;
}
……
else {
Sentence body n + 1 ·;
}

If (relational expression 1){

Statement body 1;

}Else if (relational expression 2){

Statement body 2;

}

……

else {

Sentence body n + 1 ·;

}