Presentation is loading. Please wait.

Presentation is loading. Please wait.

Loops in LabVIEW (while,for and case)

Similar presentations


Presentation on theme: "Loops in LabVIEW (while,for and case)"— Presentation transcript:

1 Loops in LabVIEW (while,for and case)
Prepared by: JENNI Amal LASSOUED Hèla IIA4/G2

2 PLAN 1)Introduction 2)subject 3) About structure 4)Applications 5)quiz

3 Introduction LabVIEW:
Is a graphical programming language using the notion of data flow Integrates the acquisition, analysis, processing and presentation of data. Is a tool for designing and implementing used to foster the intuitive approach of the programmer or user Is based on familiar tools ,easy to use for programming like program structure, arithmetic functions…

4 what is a structure? Why we used?
introduction what is a structure? Why we used? Structures: are graphical representations of loops and condition statements in textual programming languages​​. are used in the diagram to repeat blocks of code and to execute code conditionally or in a specific order. They control the flow of data in a VI These structures has many types like : Sequence Structure ,structure of repetition ,control of choice..

5 Presentation of the subject
While loop For loop Case loop

6 subject How to create For , While and Case loops?
what is the difference between loops? when the appropriate time would be to use them in your program? Which are the other concept related to these loops? What can we do with loops?

7 How to create For , While , and Case loops? Select your loop Framing the code that must be repeated. 3. Place additional nodes (Boolean control: stop button for example) and connect them.

8 While loop: what is the difference between loops?
Similar to a do loop or repeat until loop in text-based programming . is a control flow statement you use to execute a block of the subdiagram code repeatedly until a given Boolean condition is met.

9 While loop: what is the difference between loops? Contains:
The conditional terminal, defines when the loop stops. There are two settings for the conditional terminal: Continue if True :the while loop runs only if a Boolean value of true is Sent to the terminal Stop if True: the loop halts execution, when a Boolean value of true is sent to the conditional terminal The stop button can be enabled,disabled or disabled & grayed we can also choose the button behavior default will be the end condition "stop if true“. You can switch the conditional terminal to Continue if true, just a right-click on the conditional terminal.

10 what is the difference between loops?
The iteration terminal is an output terminal that contains the number of completed iterations. The iteration count always starts at zero. During the first iteration, the iteration terminal returns 0. it runs at least one faith as the continuation test is done at the end It is better to relate the conditional terminal to one condition to stop because it can lead to an infinite loop.

11 For loop: executes a subdiagram a set number of times
what is the difference between loops? For loop: executes a subdiagram a set number of times contains a count terminal. The count terminal dictates how many times the subdiagram is executed. The iteration count, always starts at zero. During the first iteration, the iteration terminal returns 0. It is possible to place a while loop and then changed to a for loop and screw it to.

12 what is the difference between loops?
the terminal count must be an integer ,if for example it assigns a float, labview retrieve only the integer part. if N = 0 or a negative value ,the loop will not run you can choose the value of N: in an explicit way: you connect a value outside the loop on the entered N in an implicit way :by a self-indexing: For each loop for ,the output value will be stored in a table and added to the given lap before: we can added a conditional terminal us a result the execution of the action would be controlled not only by the count terminal but also by the conditional terminal .

13 Case loop: what is the difference between loops?
The structure condition contains at least two sub-diagrams. The structure will execute a single sub-diagram according to the criterion of selection .. The selection criterion can be either a boolean, an integer or a string. case selector label:contains the name of the selector value Selector terminal:It determinate which case executes. if we enter a selector value that does not match the type of object associated with selector terminal : the value appears red to indicate that we must delete or edit the value Must specify a default case to handle cases that do not belong to our selection(click right button)

14 what is the difference between loops?
Case loop can not use a point number floating To The case . otherwise labVIEW rounded value to the nearest integer value. if at least one case is not bound to a tunnel, labview does not know what to put in the tunnel the center of the tunnel will be white There are for types of case structure: 1) Integer Case Structure 2)Boolean Case Structure 3)String Case Structure 4)Enumerated Case Structure

15 when we must use each type of loop?
1-While loop: When one does not know in advance the number of iteration to execute It is necessary to change the condition inside the loop, to avoid an infinite loop which is true all the time.. is changed dynamically allocating memory 1-For loop: We used for loops, where it is known from the begening how much a program must be run. the compiler can properly allocated and knows the correct memory size there is no need to calculate termination condition at each iteration both of the two loops preserve information through multiple iterations with shift register,or feedback nodes. Case loop: when the program has performed different actions, depending on the value of the selection criterion.

16 Which are the other concept related to these loops?
Tunnels: it allows the passage of data to and from the structure it appears as a solid block on the Border of the loop and has a color that matches the type of data the data passed to the outside if the execution of the loop terminates even if the data come from outside the loop runs only if all data are available There is two types of tunnel: In for loop ,auto indexing is anabled by default In while loop ,auto_indexing is disabled by default Auto-indexed tunnel disabled Auto-indexed tunnel enabled

17 Witch are the other concept related to these loops?
Shift registre: usually when programming with loops we need data from Previous iterations. it appears as a pair of opposite terminal It takes data from the right side and left side refer to the next iteration

18 Haw to Create: Right click on one edge of the loop>> "Add a shift register"
We can use several shifts register. Register transmit all data’s type and automatically changed to the same type of the first object wired to the tunnel. The initialization of the shift register is important to avoid Error!

19 Stacked shift registrer:
it lets out a values ​​from several previous iterations to use in the next iteration it must be in the left side because in the right it only allows to transfer data from the current iteration to next . Feedback Node: It’s used to store data from a previous VI or loop execution. Because a Feedback Node stores only one data value at a time, the node is useful in storing and retrieving state information from the previous execution. it should be initilized to avoid erreur

20 Creating table using loops:
Can we use loops to create others structure? Creating table using loops: if we use a while loop we right click on the tunnel resulting and we select "enable indexing.” if you use a for loop indexing is enabled by default. the tunnel output is an array of all values ​​of the VI or function returns after each iteration of the loop. If we disable the auto-indexing on an output tunnel, only the element of the last iteration of the loop passes to the next node in the diagram The most efficient method for creating an array is: Using a For loop with Auto-indexing

21 Paralell loops: can handle multiple tasks simultaneously and independently passing data between multiple loop without creating a data dependency pay attention to problems of coordination and communication between loops to avoid data dependency we must not use ware to pass data between loops running in parallel the wire creates a dependency of information because it imposes on the second loop do begin to run only if the first finished and passes information

22 State machine: state machine can easily change the order of execution states and makes decisions at each new state. It consists of a while loop that toggles from one state to another, a shift register to another .. Plotting data: thanks to the loops we can draw curves as they provide a multitude of points Master slave: It is used when you have two or more processes that need to run simultaneously and continuously but at different rates. The Master/Slave pattern consists of multiple parallel loops The master loop controls all of the slave loops, and communicates with them using messaging architectures.

23 Application:

24 Application 2:

25 Quiz: 1) For a for loop, if N = 7 what are the possible values ​​at the node iteration i? 2)Under which of the following conditions does a For loop stop executing? a. When a false value is present at the conditional terminal and the conditional terminal is b. When the value of the iteration terminal , is one less than the value of the count terminal, c. When the value of the iteration terminal, , is one more than the value of the count terminal, d. None of the above

26 3) Elements "exit 1" and "exit 2 " indicate they have the same value during program execution.
4)What are the values ​​of "a ", "b", "c " and "Boolean" at the end of the code enforcement

27 Thanks for your attention


Download ppt "Loops in LabVIEW (while,for and case)"

Similar presentations


Ads by Google