[Control Structures]
描述
break
is used to exit from a for
, while
或 do…while
loop, bypassing the normal loop condition. It is also used to exit from a switch case
statement.
範例程式碼
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); }
語法參考主頁面
86Duino 參考的文本是根據 Creative Commons Attribution-ShareAlike 3.0 License,部分文本是從 the Arduino reference 修改的。 參考中的代碼示例已發佈到公共領域。