return
终止函式的执行,同时也可以将一个值传回至之前呼叫的函式。
语法
return;
return value; // 两种语法都成立
参数
value
: 可以是任何变数或常数型别。
范例
一个用来比对感测器输入是否达到阀值的函式:
int checkSensor(){ if (analogRead(0) > 400) { return 1; else{ return 0; } }
用return的话可以简单的去测试一段程式码,而不需要去注解掉一大段很可能有bug的程式码。
void loop(){ // 需要被测试的程式码 return; // 要被略过的程式码 }
See also
- comments
本页由热血青年 LBU 译自英文版。
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.