Reference.Return History

Hide minor edits - Show changes to output

April 03, 2008, at 08:15 PM by Paul Badger -
Changed lines 9-10 from:
return value;
to:
return value; // both forms are valid
October 09, 2007, at 05:32 AM by Paul Badger -
Changed lines 18-19 from:
[@
int checkSensor(){
to:
[@ int checkSensor(){
October 09, 2007, at 05:32 AM by Paul Badger -
Deleted line 17:
July 17, 2007, at 06:28 AM by Paul Badger -
Changed lines 5-6 from:
!! Syntax:
to:
!!!! Syntax:
Changed lines 11-12 from:
!!! Parameters
to:
!!!! Parameters
July 17, 2007, at 06:28 AM by Paul Badger -
Changed lines 11-12 from:
!! Parameters
to:
!!! Parameters
July 17, 2007, at 06:26 AM by Paul Badger -
Added line 31:
July 17, 2007, at 06:25 AM by Paul Badger -
Changed lines 37-39 from:
}

to:
}@]

July 17, 2007, at 06:23 AM by Paul Badger -
Changed lines 42-43 from:
[[comment | comment]]
to:
[[Comments | comments ]]
July 17, 2007, at 06:22 AM by Paul Badger -
Changed lines 3-4 from:
Terminate a function and return a value to the calling function if desired.
to:
Terminate a function and return a value from a function to the calling function, if desired.
Changed lines 26-43 from:
}@]
to:
}@]

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

[@void loop(){
// brilliant code idea to test here

return;

// the rest of a dysfunctional sketch here
// this code will never be executed
}


!!!! See also

[[comment | comment]]
July 17, 2007, at 06:14 AM by Paul Badger -
Added lines 1-26:
!! return

Terminate a function and return a value to the calling function if desired.

!! Syntax:

return;

return value;

!! Parameters

value: any variable or constant type

!!!! Examples:

A function to compare a sensor input to a threshold

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

Share