“Break”的版本间的差异
(Created page with "https://www.microduino.cn/wiki/index.php/Arduino_语法手册/zh 返回Arduino语法手册") |
|||
| 第1行: | 第1行: | ||
| + | *'''break''' | ||
| + | break用于退出do,for,while循环,能绕过一般的判断条件。它也能够用于退出switch语句。 | ||
| + | |||
| + | *'''例子''' | ||
| + | <pre style="color:green"> | ||
| + | |||
| + | for (x = 0; x < 255; x ++) | ||
| + | { | ||
| + | digitalWrite(PWMpin, x); | ||
| + | sens = analogRead(sensorPin); | ||
| + | if (sens > threshold){ // 超出探测范围 | ||
| + | x = 0; | ||
| + | break; | ||
| + | } | ||
| + | delay(50); | ||
| + | } | ||
| + | </pre> | ||
| + | |||
[[https://www.microduino.cn/wiki/index.php/Arduino_%E8%AF%AD%E6%B3%95%E6%89%8B%E5%86%8C/zh 返回Arduino语法手册]] | [[https://www.microduino.cn/wiki/index.php/Arduino_%E8%AF%AD%E6%B3%95%E6%89%8B%E5%86%8C/zh 返回Arduino语法手册]] | ||
2016年3月28日 (一) 07:31的最新版本
- break
break用于退出do,for,while循环,能绕过一般的判断条件。它也能够用于退出switch语句。
- 例子
for (x = 0; x < 255; x ++)
{
digitalWrite(PWMpin, x);
sens = analogRead(sensorPin);
if (sens > threshold){ // 超出探测范围
x = 0;
break;
}
delay(50);
}