# Functions

The functions folder contains all the blocks you need to create functions. Functions are a fundamental concept in programming that allow you to group blocks and code together to execute it as a single unit. They are like reusable blocks of code that can be called from different parts of your program, making your code more modular and easier to manage.

Functions are a powerful tool for writing structured, maintainable, and reusable code in Blockly. By mastering the use of functions, you can significantly improve the quality and efficiency of your programs.&#x20;

<figure><img src="https://3732834919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrpyhVmLjv9Bu7tKDF8HF%2Fuploads%2FaydZtMeIePixBoYXrBoX%2Fimage.png?alt=media&#x26;token=fc3f7117-2e2f-4049-a35d-7d65c9957294" alt=""><figcaption><p>function blocks</p></figcaption></figure>



### Function without output

<figure><img src="https://3732834919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrpyhVmLjv9Bu7tKDF8HF%2Fuploads%2FcyOZCJUXqrHMBBT2XYER%2Fimage.png?alt=media&#x26;token=14505c41-78b0-4c45-84c2-4a930b676f24" alt=""><figcaption><p>function without output block</p></figcaption></figure>

This block represents a function without an input. Its built out of different parts:&#x20;

* In the image, the "do something" is the name of the functions that will be recalled in the code. It's important to use different names for the functions.
* By clicking on the question mark you can add a description of the function, this can be useful when you need to debug your code or explain to other programmers what your code is doing in that part.&#x20;
* By clicking on the gear you can choose which input to insert into your function.&#x20;
* The part inside the block, between the connect and the socket will contain all the sequences  that the function will need to perform.



### Function with outputs

<figure><img src="https://3732834919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrpyhVmLjv9Bu7tKDF8HF%2Fuploads%2FyHrEyyOSLlq4VQOGjUyY%2Fimage.png?alt=media&#x26;token=a9df055c-1f69-44ac-a3b9-212176845e9c" alt=""><figcaption><p>function with outputs block</p></figcaption></figure>

This blocks is virtually identical to the previous block described but it returns an output that you've chosen. Instead, when statements are not allowed this function "closes" the gap and when it's called it will return what you add to the return socket.



### Check condition

<figure><img src="https://3732834919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrpyhVmLjv9Bu7tKDF8HF%2Fuploads%2FE3adpIgqMCXfAkKUApRk%2Fimage.png?alt=media&#x26;token=3a037ef0-3f56-4120-921a-0adedfc762d6" alt=""><figcaption><p>check condition block</p></figcaption></figure>

Note: This block can only be used in a function.&#x20;

With this block, you can check a condition. If the value put in the 'if' socket is true then it will return the value in the 'return' socket. If the value is not true the function will end the program.



### Call function&#x20;

<figure><img src="https://3732834919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrpyhVmLjv9Bu7tKDF8HF%2Fuploads%2FLtbCbgEmzDoNYss8Rnz9%2Fimage.png?alt=media&#x26;token=268ee0bb-5176-4f57-9522-2db1e07e4c47" alt=""><figcaption><p>call function block</p></figcaption></figure>

In order to call a function you must create a do something block and give it the same name as the function you want to call. &#x20;
