break

[Control Structures]

説明

break is used to exit from a forwhile または do…​while loop, bypassing the normal loop condition. It is also used to exit from a switch case statement.

Example Code

In the following code, the control exits the for loop when the sensor value exceeds the threshold.

int threshold = 40;
for (int x = 0; x < 255; x++) {
  analogWrite(PWMpin, x);
  sens = analogRead(sensorPin);
  if (sens > threshold) {     // bail out on sensor detect
    x = 0;
    break;
  }
  delay(50);
}

Language Reference Home

86Duino のリファレンスのテキストは Arduino レファレンス を編集したもので、 Creative Commons Attribution-ShareAlike 3.0 License下でライセンスされています。リファレンス内のコードサンプルはパブリックドメインとして公開されています。

コメントする

上部へスクロール