if 語句后面可以跟隨一個可選的 else if ... else 語句,其對于測試各種條件非常有用。
當使用 if ... else if ... else 語句時,請記?。?
一個 if 可以有0或一個else語句,它必須在所有else if之后。
if 可以有0到多個else if語句,它們必須在else之前。
一旦 else if 成功,將不會測試剩余的else if或else語句。
if (expression_1) { Block of statements; } else if(expression_2) { Block of statements; } . . . else { Block of statements; }
/* Global variable definition */ int A = 5 ; int B = 9 ; int c = 15; 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 */ else if ((A == B )||( B < c) ) /* if condition is true then execute the following statement*/ { C = B* A; }else c++; }
更多建議: