Arduino - if...else 语句



一个if语句可以跟随着一个可选的else语句,当表达式为假时执行。

if...else 语句语法

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

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

If Else Statement

示例

/* 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;
   }
}
arduino_control_statements.htm
广告