Difference between revisions of "Mixly Block Category - Functions"

From Microduino Wiki
Jump to: navigation, search
(Create a Procedure/Function)
Line 1: Line 1:
 +
Segmenting code into functions allows a programmer to create modular pieces of code that perform a defined task and then return to the area of code from which the function was "called". The typical case for creating a function is when one needs to perform the same action multiple times in a program.
 +
 +
 +
Read more here: https://www.arduino.cc/en/Reference/FunctionDeclaration
 
=Create a Procedure/Function=
 
=Create a Procedure/Function=
*Without Return
+
Functions can take in Variables. These variables are passed to the functions and used by the function. These variables are known as parameters or '''inputs'''. Functions can be created with a '''return''', which means the '''Function''' will return a value after execution is complete.
*With Return
+
 
 +
==Configuring Input==
 +
Input variables can be passed to Functions / Procedures which can be used in the encapsulated set of blocks. To configure how many Input Variables there are. Simply click on the gear icon and drag the amount of variables and define the type for each.
 +
==Without Return==
 +
This block encapsulates a set of blocks that execute. There is no return, which means no value is returned after the function is done.
 +
*Function / Procedure Name - Give a name to the function / procedure. Used to reference when calling the function / procedure.
 +
==With Return==
 +
This block encapsulates a set of blocks that execute. There is return, which means a value is returned after the function is done.
  
==Configuring with Parameters==
 
  
 
=If ... then ... return=
 
=If ... then ... return=
 +
This block is used to check a condition and if '''true''' will return immediately (exit the function).
 +
*Condition - Variable or statement that evaluates to a bool. If '''true''', a return occurs, which exits the function. If false, then skip to the next block.
  
 
=After Creating a Procedure/Function=
 
=After Creating a Procedure/Function=
 
==Call a Procedure/Function==
 
==Call a Procedure/Function==

Revision as of 00:10, 28 February 2017

Segmenting code into functions allows a programmer to create modular pieces of code that perform a defined task and then return to the area of code from which the function was "called". The typical case for creating a function is when one needs to perform the same action multiple times in a program.


Read more here: https://www.arduino.cc/en/Reference/FunctionDeclaration

Create a Procedure/Function

Functions can take in Variables. These variables are passed to the functions and used by the function. These variables are known as parameters or inputs. Functions can be created with a return, which means the Function will return a value after execution is complete.

Configuring Input

Input variables can be passed to Functions / Procedures which can be used in the encapsulated set of blocks. To configure how many Input Variables there are. Simply click on the gear icon and drag the amount of variables and define the type for each.

Without Return

This block encapsulates a set of blocks that execute. There is no return, which means no value is returned after the function is done.

  • Function / Procedure Name - Give a name to the function / procedure. Used to reference when calling the function / procedure.

With Return

This block encapsulates a set of blocks that execute. There is return, which means a value is returned after the function is done.


If ... then ... return

This block is used to check a condition and if true will return immediately (exit the function).

  • Condition - Variable or statement that evaluates to a bool. If true, a return occurs, which exits the function. If false, then skip to the next block.

After Creating a Procedure/Function

Call a Procedure/Function