课程表

Arduino 基础

Arduino 函数库

Arduino 进阶

Arduino 项目

Arduino 传感器

Arduino 电机控制

Arduino 声音

工具箱
速查手册

Arduino If..else if ..else语句

当前位置:免费教程 » 程序设计 » Arduino

if 语句之后可以有一个可选的 else if ... else 语句,这对于使用single if ... else if语句测试各种条件非常有用。


当使用 if ... else if ... else 语句时,请记住 -

  • 一个 if 可以有零或一个else语句,它必须在任何其他if之后。

  • if 可以有0到多个else if语句,它们必须在else之前。

  • 一旦 else if 成功,将不会测试剩余的其他if或else语句。


if ... else if ... else语句

  1. if (expression_1) {
  2. Block of statements;
  3. }
  4.  
  5. else if(expression_2) {
  6. Block of statements;
  7. }
  8. .
  9. .
  10. .
  11.  
  12. else {
  13. Block of statements;
  14. }


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


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


例子
  1. /* Global variable definition */
  2. int A = 5 ;
  3. int B = 9 ;
  4. int c = 15;
  5.  
  6. Void setup () {
  7.  
  8. }
  9.  
  10. Void loop () {
  11. /* check the boolean condition */
  12. if (A > B) /* if condition is true then execute the following statement*/ {
  13. A++;
  14. }
  15. /* check the boolean condition */
  16. else if ((A == B )||( B < c) ) /* if condition is true then
  17. execute the following statement*/ {
  18. C = B* A;
  19. }else
  20. c++;
  21. }
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号