aboutsummaryrefslogtreecommitdiffstats
path: root/source/arduino/return.rst
blob: ae3b37df8423edfe6417422b41e9bb5e9850f4fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
.. _arduino-return:

return
======

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



Syntax:
-------

return;



return value; // both forms are valid



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;
        }
    }



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
--------

`comments <http://arduino.cc/en/Reference/Comments>`_