LabView Structures: For Loop and Case (Switch) EN/ES

When I look at the data handling structures in LabView I can really notice how complicated it could be to use for a programmer who only knows programming languages by code with no previous experience or knowledge in LabView.

It even happened to me that at the beginning I tried to do things that I was used to do in C with structures like switch but it was so tangled that I had to go to the help function to try to find the right way, that was strangely funny for me but not everyone has the same sense of humor to complications and frustrations can lead to abandonment.

Continuing with the LabView structures in this article we will see some details about the use of For and Case, assuming that the reader is able to use them in a basic language like C we will not fall into the temptation to write a wikipedia about them and we will only see how to adapt the LabView structures to the form that we commonly know.


Cuando miro las estructuras para manejo de datos en LabView realmente puedo notar como podría resultar complicado su uso para un programador que solo conozco lenguajes de programación por código sin experiencia ni conocimientos previos en LabView.

Incluso me pasó que al inicio intentaba hacer cosas que estaba acostumbrado a hacer en C con estructuras como switch pero fue tan enredado que tuve que acudir a la función de ayuda para intentar buscar la forma correcta, aquello fue extrañamente divertido para mi pero no todos tienen el mismo sentido del humor ante las complicaciones y las frustraciones pueden llevar al abandono.

Siguiendo con las estructuras de LabView en este artículo vamos a ver algunos detalles sobre el uso de For y Case, asumiendo que el lector esta en capacidad de usarlas en un lenguaje básico como C no vamos a caer en la tentación de escribir una wikipedia sobre estos y solo vamos a ver cómo adaptar las estructuras de LabView a la forma que comúnmente conocemos.


We can assume the FOR loop as extremely identical to the WHILE loop explained in the previous article with the exception that a FOR loop cannot remain in execution an infinite number of times, perhaps it can be manipulated to occur but it is not its nature.

Then a FOR has a limited number of repetitions, to achieve this we commonly created a variable that increases or decreases its value until certain level in which already fulfilled it leaves the FOR.

Said with other words the FOR is like a WHILE whose code will be executed a predefined number of times but in addition we can take advantage of the variable that increases and decreases to take actions in the contained code. Now let's see how something basic would look like in a FOR structure that fulfills the same function as if we were using C.


Podemos asumir el bucle FOR como en extremo idéntico al WHILE explicado en el Articulo anterior con la salvedad de que un bucle FOR no puede permanecer en ejecucion un numero infinito de veces, tal vez se pueda manipular que ocurra pero no es su naturaleza.

Entonces un FOR tiene un numero limitado de repeticiones, para lograr esto comúnmente creábamos una variable que incrementa o decrementa su valor hasta cierto nivel en el que ya cumplido se sale del FOR.

Dicho con otras palabras el FOR es como un WHILE cuyo código se ejecutará un numero predefinido de veces pero además podemos aprovechar la variable que incrementa y decrementa para que tome acciones en el código contenido. Ahora veamos como se veria algo básico en una estructura FOR que cumpla la misma función que si usaramos C.



Unlike the While Loop now we see a blue N in the upper right corner, in this we establish the number of times that the internal code is going to be executed, we can also use a connection that decrements this value in each execution and in this way we obtain the variable in decrement.

If we want the variable in increment we take it from the iteration counter, in this case I have only placed an indicator so that we can visualize its behavior, we can notice that there is not a stop icon as in While loop, it is like this because when the quantity of predefined iterations occurs the loop stops automatically.

Two Leds will alternate between on and off in each iteration, in addition we continue making use of the delay timer, we could even set the delay in 1 second and make the FOR a timer of any kind. The front panel of this structure has the following shape:


A diferencia del While Loop ahora vemos una N azul en la esquina superior derecha, en esta establecemos el numero de veces que se va a ejecutar el código interno, también podemos usar una coneccion que decremente este valor en cada ejecución y de esa forma obtenemos la variable en decremento.

Si queremos la variable en incremento lo tomamos del contador de iteraciones en este caso solo he colocado un indicador para que visualicemos su comportamiento, podemos notar que no hay un icono de parada como en While loop, es así porque al ocurrir la cantidad de iteraciones predefinidas el bucle se detiene automáticamente.

Dos Leds alternaran entre encendido y apagado en cada iteración, además seguimos haciendo uso del temporizador de retardo, incluso podríamos establecer el retardo en 1 segundo y hacer del FOR un temporizador cualquiera. El panel frontal de esta estructura tiene la siguiente forma:


In FOR COUNT a user can determine the number of executions to be performed, FOR ITERATIONS shows the iterations in increasing order, milliseconds to wait sets the time between each execution and x-1 shows the number of executions in decreasing order.


En FOR COUNT un usuario puede determinar el numero de ejecuciones que se realizaran, en FOR ITERATIONS se observan las iteraciones en orden creciente, milliseconds to wait se establece el tiempo entre cada ejecución y x-1 muestra el numero de ejecuciones en orden decreciente.


CASE

For the execution of this structure we must connect the selector to the question mark, the selector is the one that will give the values for each case and for each value a case must be established, if the selector is of boolean type only TRUE and FALSE cases will exist, if it is numeric a case must be created for each value, if several sequential values share the same case the case can be placed as value1. .value2, if they are not sequential they are separated by comma, value1,value3, a case must also be established for indeterminate values, in this case the value is written as default.


Para la ejecución de esta estructura debemos conectar el selector al signo de interrogación, el selector es el que dará los valores para cada caso y para cada valor se debe establecer un caso, si el selector es de tipo booleano solo existirán los casos TRUE y FALSE, si es numérico se debe crear un caso para cada valor, si varios valores secuenciales comparten el mismo caso se puede colocar el caso como valor1..valor2, si no son secuenciales se separan por coma, valor1,valor3, también se debe establecer un caso para valores indeterminados, en este caso el valor se escribe como default.


The structure that we see is inside a while loop because otherwise only one case would be executed and the program would stop, the selector is a dial of 6 values ranging from 0 to 5, what each case does in ascending order is to turn on a led to form a led bar, if the value is zero the lowest one is turned on and turns off the others, if it is 1 it turns on the first two and turns off the others and so on. But I will not try to explain in detail something that we can see graphically 😅.


La estructura que vemos esta dentro de un while loop ya que de no ser así solo se ejecutaría un caso y se detendría el programa, el selector es un dial de 6 valores que van del 0 al 5, lo que hace cada caso en orden ascendente es encender un led para formar una barra de led, si el valor es cero se enciende el mas bajo y apaga los demas, si es 1 enciende los dos primeros y apaga los demas y asi sucesivamente. Pero no voy a intentar explicar a detalle algo que podemos ver gráficamente 😅.


Next we will see how the FOR LOOP acts, let's take into account the number of iterations and observe that the predetermined amount in N is executed, then the execution of what is inside the structure is stopped, on the other hand the CASE will be executed continuously until we stop it manually thanks to the fact that it is in a While Loop with manual stop.


A continuación veremos como actúa el FOR LOOP, tomemos en cuenta el numero de iteraciones y observemos que se ejecuta la cantidad predeterminada en N, luego se detiene la ejecución de lo que esté dentro de la estructura, por otro lado el CASE se ejecutara de forma continua hasta que lo detengamos de forma manual gracias a que esta en un While Loop con parada manual.









https://images.ecency.com/p/3W72119s5BjW4PvRk9nXBzqrPWMsMTjNrXDPFFf12CAfRz5MY8jCm5vGDUj7o96hwAT3YCMBJgcTgcWmsqeuBbZL1YbmxtaV4gyfByenDkmAkgv6rkm9ZP.webp?format=webp&mode=fit



0
0
0.000
1 comments
avatar

Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

Thanks for including @stemsocial as a beneficiary, which gives you stronger support. 
 

0
0
0.000