Arduino - if 語句



它接收一個括號內的表示式和一個語句或語句塊。如果表示式為真,則執行該語句或語句塊,否則跳過這些語句。

if 語句的不同形式

形式 1

if (expression)
   statement;

如果只有一個語句,則可以使用不帶花括號 { } 的 if 語句。

形式 2

if (expression) {
   Block of statements;
}

if 語句 – 執行順序

IF 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++;
   /* check the boolean condition */
   If ( ( A < B ) && ( B != 0 )) /* if condition is true then execute the following statement*/ { 
      A += B;
      B--;
   }
}
arduino_control_statements.htm
廣告