Arduino教程20.Arduino If语句

它采用括号中的表达式,后面跟随语句或语句块。如果表达式为真,则执行语句或语句块,否则跳过这些语句。

不同形式的if语句

形式1

if (expression)
   statement;

如果你有一个语句,你可以使用没有大括号{}的if语句。

形式2

if (expression) {
   Block of statements;
}

if语句 – 执行顺序

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--;
   }
}

发布者:suiyublg,转转请注明出处:https://huibian.net/1008-3/

(0)
suiyublg的头像suiyublg
上一篇 2017年3月23日 17:39
下一篇 2017年3月24日 17:51

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
欢迎大家来到大雄学编程!