Arduino 的 do-while 迴圈


do-while 迴圈在 Arduino 中的語法 與在 C 中的語法類似。如下所示 −

do{
   //Code
} while (condition);

注意末尾的分號。

示例

void setup() {
   // put your setup code here, to run once:
   Serial.begin(9600);
   Serial.println();

   int i = 5;
   do{
      Serial.println(i);
      i--;
   } while(i > 0);

}

void loop() {
   // put your main code here, to run repeatedly:
}

輸出

序列埠監視器的輸出如下所示 −

更新於: 2021 年 5 月 29 日

1K+ 瀏覽量

開啟你的職業

完成課程即可獲得認證

開始
廣告
© . All rights reserved.