它采用括号中的表达式和语句或语句块。 如果表达式为真,则执行语句或语句块,否则跳过这些语句。
不同形式的if语句
表单1
- if (expression)
- statement;
如果你有一个语句,你可以使用if语句没有大括号{}。
表单2
- if (expression) {
- Block of statements;
- }
if语句 - 执行顺序

- /* 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--;
- }
- }
转载本站内容时,请务必注明来自W3xue,违者必究。