[:es]En esta entrada se explican el conjunto de instrucciones disponibles para el control de flujo de un programa en Facilino.
¿Qué es el control de flujo?
En los microcontroladores como Arduino, el flujo del programa, esto es el orden de ejecución de las instrucciones, es normalmente secuencial. Es decir, las instrucciones se ejecutan en el orden en el que aparecen. En Facilino, la «secuencialidad» se obtiene al apilar las instrucciones una detrás de otra. Afortunadamente, podemos modificar el flujo de un programa mediante las instrucciones que alteran qué instrucción se ejecutará a continuación dadas determinadas condiciones.
Arduino dispone de dos funciones que deben estar siempre en todo programa para que compile adecuadamente. La función «setup» permite ejecutar código que queremos que se ejecute una sola vez al inicio, cuando arranca el microcontrolador. La función «loop» permite ejecutar código que queremos que se repita sucesivamente.
El control de flujo se puede realizar mediante bucles que nos permitirán repetir un conjunto de instrucciones hasta o mientras se cumpla una determinada condición o mediante instrucciones de salto condicional que nos permitirán ejecutar determinadas instrucciones sí y sólo sí se cumplen determinadas condiciones, de lo contrario no se ejecutarán.
Dentro de las instrucciones de control de flujo también están incluidas instrucciones que tienen que ver con la espera. Esto es así para asegurarse que ha transcurrido un determinado tiempo o condición hasta continuar con la siguiente instrucción.
Inicio/Repetir
Todo programa de Facilino deberá incorporar esta instrucción. El código que pongamos en el contenedor «Inicio» sólo se ejecutará una vez al inicio del programa, mientras que el código que pongamos en el contenedor «Repetir» se ejecutará repetidamente.

Bucles
Las instrucciones de bucle en Facilino permiten implementar bucles «while», «for» o «do… while» de Arduino. Este tipo de instrucciones os permitirán repetir determinado conjunto de instrucciones (las que pondremos dentro del contenedor de la instrucción) un número de veces. La diferencia entre la instrucción «while» y «do…while» es que en la primera se evalúa la condición y en caso de ser cierta entonces se ejecuta el código del contenedor, mientras que en la segunda, se ejecuta primero el código y luego se evalúa la condición para determinar si se debe repetir o no. Las instrucciones del tipo «for» permiten repetir un número de veces «pre-fijado» una tarea.

Los bucles pueden ser interrumpidos mediante la siguiente instrucción:
![]()
o también podemos «saltar» a la siguiente iteración del bucle con la siguiente instrucción (en determinadas ocasiones conviene no seguir ejecutando lo que queda de iteración y preferimos continuar con la siguiente iteración):
![]()
Salto condicional
Las instrucciones de salto condicional en Facilino permiten ejecutar unas instrucciones «si» se cumple la condición de entrada. Existen dos tipos de instrucciones correspondientes a las instrucciones «if» y «switch» en Arduino. La primera permite ejecutar una condición binaria y pueden agregarse casos de «en cambio, si» o «de lo contrario». La segunda instrucción permite evaluar un número/variable y según el valor del mismo, se ejecutará un caso u otro.

Esperas
Podemos realizar sencillas esperas de tiempo (en milisegundos) o a que se cumpla una determinada condición:

Además, podemos medir el tiempo actual desde que arrancó el programa de Arduino en milisegundos o microsegundos:

Ejemplo 1
En este ejemplo se generan números aleatorios comprendidos entre el 1 y el 20. Si el número es menor o igual a 15 entonces se muestra un mensaje indicando que se debe pulsar un botón (conectado al pin D2) y se vuelve a generar otro número aleatorio.
Ejemplo 2
En este ejemplo se generan temperaturas ficticias comprendidas entre 5ºC y 40ºC aleatoriamente. En función del valor de temperatura, se muestra un mensaje u otro, para indicar que la temperatura es demasiado alta, demasiado baja o por el contrario está perfecta.
Ejemplo 3
En este ejemplo se muestra cómo hacer parpadear un LED 10 veces.
[:en]In this post, we explain instructions related to the control flow of a program in Facilino.
What is the control flow?
In microcontrollers, the program flow, that how instructions are executed is usually sequential. This means that instructions are executed in order «as they appear». In Facilino, «sequentially» is achieved by stacking blocks one after another one. Fortunately, we can modify the flow of a program by including instructions that will modify which is the next instruction to execute based on some conditions.
Arduino has two main functions that must be included in every program to properly compile. The «setup» function allows you to include code that will be executed once at the beginning, while the «loop» function will allow you to execute code that will be endlessly repeated.
Flow control can be achieved with loops that will allow us to repeat a set of instructions until a condition is met or conditional jump instructions that will determine wether a code will be executed or not.
Within the flow control instructions, we can also find instructions related to delays that will simply wait until a given condition is met or a time has passed by before the next instruction is executed.
Setup/Loop
Every Facilino program will include this instruction. The blocks included in the «Setup» container will be executed just once, while the block instructions included in the «Loop» container will be executed endlessly.

Loops
Loops instructions in Facilino implement «while», «for» and «do… while» instructions in Arduino. This type of instructions will allow you to execute a set of instructions (whatever we put inside the «do» container) until a condition is met. The difference between «while» and «do…while» is that instructions contained in a «while» block will be executed if the condition is met, while the instructions contained in a «do…while» block will be executed first and after that, the condition will be evaluated. A «for» block will iterate over a variable a given number of times to repeat a task.

Loops can be interrupted with a «break» instruction. Also, we might be interested in continuing with the loop by «jumping» the remainder of the code of the iteration:

Conditional jumps
Conditional jump instructions in Facilino allow you to execute a code «if» a given condition is met. There are two types of blocks «if» and «switch». The «if» block evaluates a binary expression and if it is true, then executes the code inside the container. Additional branches can be created by adding «else if» and «else» blocks in the mutator. A «switch» block instruction evaluates a number and depending on its value executes one case or another.

Delays
We can create simple delays of time (in milliseconds) or wait until a condition is met:

We can also meassure the current time from start in microseconds or milliseconds:

Example 1
In this example we generate random numbers between 1 and 20. If the number is lower or equal than 15, then we show a message indicating that we must press a button switch (connected to pin D2) and generate another random number.
Example 2
In this example we generate ficticious temperatures between 5ºC and 40ºC randomly. Based on the temperature value, we show messages indicating that the temperatures is too high, too cold or simply perfect.
Example 3
In this example we show how to blink a LED 10 times.
[:]