> For the complete documentation index, see [llms.txt](https://vrs-guidebook-2nd-edition.gitbook.io/vrs-guidebook-2nd-edition/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vrs-guidebook-2nd-edition.gitbook.io/vrs-guidebook-2nd-edition/programming/blocks/function.md).

# Function

A function is a reusable block of code that performs a specific task. It's like a mini-program within your main program. You give it a name, define what it does, and then you can "call" or use it multiple times in your code without having to write the same instructions repeatedly.

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfPBNVlgrAw_l-a9k-uZwmJ7FizYabnP4fos811UUpGuTOGG0ZUoTxdB77o45qEMs2XJXwJMJozcJ2bLDN9i4YAtjSrmNRInoYCI9p9czKO3z-Cf84jtE1rVVWoPy7VU-Kxi3Ok5KWVppjaPkm3WnvkioIs?key=hRw9bBhBfp1lHBJ7rUAI2Q)

**to do something**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfGJFB53z0ZBkvWpqbLdW9YkEVfjgZjgYHBYaCFRTRw8DK9XTFqqXcYdp0ZPWAbVwwn6pIHa0sex3IOHZuhsCH9K-Ywr36rrIHV1Qzmh70qmiRswuzJpV57g33rcDm4WNz08BddpCqkZXGN6xEaVf0kuwHz?key=hRw9bBhBfp1lHBJ7rUAI2Q)

Creates a function with no output.

Key points:

* You can change “do something” to a unique tag for your future reference.
* This function has no output.

**to do something return**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXd9-dAApbxlEsdJ_cjDcZQCpjd720NX5QDaRO49TT1POpqr4JNVANytYlh9kixCb0jsrd3AsJ7UdaeQweIDAA8lfKHZD9ylTIY_1hubbxd5KdqyBalM6LBRBCZPGPxGJyMfQ7Eg_T1yiUfav6lWCby7nw1j?key=hRw9bBhBfp1lHBJ7rUAI2Q)

Creates a function with an output.

Key points:

* You can change “do something” to a unique tag for your future reference.
* This function returns a value as specified.

**if return**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXc_eE5AllPcYagbl7LA-2LaHt_xbAXMeogTrA78a6JDYxaQHZVy4VLYkeWq1b_ERybipLryN6Vw7oEeeg2jYMSmZ8MbA6RG1Yk1hHgHnZFRUjqGaVdXah1TQgjtu-2NwXzu7faCW_qgv0YsyJhjbXuqx-4?key=hRw9bBhBfp1lHBJ7rUAI2Q)

If a value is true, then return the second value.&#x20;

Key points:

* This block can only be used within a function.
* When the condition is true and the value is returned, no other blocks will be executed anymore.

**runOpMode**

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXfeBnXUomTDcUj2O1PBJLxVzfh3yPlQumjd6CGziOoQo8de4z9o_496ONmGtSJ8XS7Lp12d5TpohmRaAfn-GUMdlCHWmhd12EM80_5JO3I9XKRm_L2EEbprJm79DymnSZTEfv4U1k23OqXZJBSTAP8V2cY?key=hRw9bBhBfp1lHBJ7rUAI2Q)

Run the user defined function “runOpMode”. You may have defined a function with a different name. The user defined function name will auto populate in the functions list.
