当前位置: 首页 > 文档资料 > Arduino 中文教程 >

If …else statement

优质
小牛编辑
117浏览
2023-12-01

if语句后面可以跟一个可选的else语句,该语句在表达式为false时执行。

if ... else语句

if (expression) {
   Block of statements;
}
else {
   Block of statements;
}

if ... else语句 - 执行顺序

如果是其他声明

例子 (Example)

/* Global variable definition */
int A = 5 ;
int B = 9 ;
Void setup () {
}
Void loop () {
   /* check the boolean condition */
   if (A > B) /* if condition is true then execute the following statement*/ {
      A++;
   }else {
      B -= A;
   }
}