return

Descrição

Termina uma função e retorna um valor, caso desejado.

Sintaxe


return; return valor; // ambas as formas são válidas

Parâmetros

  • valor: qualquer variável ou constante de qualquer tipo de dado

Código de Exemplo

Uma função para comparar a saída de um sensor com um limiar


int checaSensor() { if (analogRead(0) > 400) { return 1; } else { return 0; } }

The return keyword is handy to test a section of code without having to "comment out" large sections of possibly buggy code.


void loop() { return; // the rest of a dysfunctional sketch here // this code will never be executed }

Testing Example


void setup() { Serial.begin(9600); printMessage(); } void loop() { } void printMessage() { Serial.println("Hello, ArduinoGetStarted.com"); return; Serial.println("Hi, ArduinoGetStarted.com"); }

The result on Serial Monitor:

COM6
Send
Hello, ArduinoGetStarted.com
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

As we can see, the text after return is not printed.

Ver Também

※ ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.

※ OUR MESSAGES

  • We are AVAILABLE for HIRE. See how to hire us to build your project
  • Any suggestion, correction, and translation? please email us at ArduinoGetStarted@gmail.com, We appreciate it
  • We mainly keep improving the references in English. See English version of this page for the latest update.