word; clear: both; text-indent: 2em; color: rgb(24, 30, 51); font-family: PingFangSC, 微软雅黑, 黑体, Arial, Helvetica, sans-serif; font-size: 18px; background-color: rgb(255, 255, 255); line-height: 2;">用 if 语句可以构成分支结构。它根据给定的条件进行判断,以决定执行某个分支程序段。C语言的 if
word; clear: both; text-indent: 2em; color: rgb(24, 30, 51); font-family: PingFangSC, 微软雅黑, 黑体, Arial, Helvetica, sans-serif; font-size: 18px; background-color: rgb(255, 255, 255); line-height: 2;">语句有三种基本形式。
if(表达式) 语句
2. 第二种形式为: if-else
if(表达式)
语句 1;
else
语句 2;
3. 第三种形式为 if-else-if 形式
前二种形式的 if 语句一般都用于两个分支的情况。 当有多个分支选择时,可采用 if-else-if 语句,其一般形式为:
if(表达式 1)
语句 1;
else if(表达式2)
语句 2;
else if(表达式3)
语句 3;
…
else if(表达式m)
语句 m;
else
语句 n;