Return

From Microduino Wiki
Revision as of 07:32, 4 August 2016 by Fengfeng (talk) (Created page with "*'''return''' To terminate a function, and if there is a return value, it will be returned to the calling function through this function. *'''Syntax:''' <pre style="color:gr...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  • return

To terminate a function, and if there is a return value, it will be returned to the calling function through this function.

  • Syntax:

return;
return value; // the two forms are both ok
  • Parameters

value:the type of any variable and constant

  • Example:

A function to compare the threshold of the sensor input


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

Keyword return can easily test a piece of code, without “commenting out” great block of possible bug code.


void loop(){
 
//write beautiful code to test here. 
 
return;
 
//the rest dysfunction of the program
//the code behind return can never be executed
}

[Return to Arduino Syntax Manual]