LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

break and continue statments in for loop

Hi,
 
How can you program break and continue statements in Labview similar to C. I want o be able to exit a for loop before all iterations are completed based on a boolean switch. Any ideas ?
 
Thanks
GM
0 Kudos
Message 1 of 15
(4,390 Views)
Don't you need a while loop?
0 Kudos
Message 2 of 15
(4,388 Views)

Hi,

You can use a while loop instead. This while loop must be stopped whenever the number of executions exceed a user defined limit or a boolean switch, that you've talked about, has been pressed.

 

0 Kudos
Message 3 of 15
(4,381 Views)

Hi,

Thanks for you response, i guess i should have figured that out. I was just curious to know if you could simulate a break or continue nevertheless problem solved. I have one more question regarding my VI, if you see the attached file in my innermost sequence structure which is labeled as Forward Direction or Reverse direction. I read an array from a Sub-VI and then take the average of the array.

How can i store the read value consecutively in an array ? So for example when i get the first value i want it to be stored in A[0], second value in A[1],.......A[267]. I tried using intilize array and all sorts of combinations but the value gets overwirtten in index 0 of the array.

Please free to make modifications to my code and send it back with suggestions

Thanks

GM

0 Kudos
Message 4 of 15
(4,372 Views)

I am not intending to insult you but your code is poorly written.  You repeat a lot of code in each sequence structure.  Actually, sequence structures are not very good for programming.  A lot of code is hidden, and a lot of code is duplicated.  Also, it is hard to read and understand.  You should revise your code and use loops to repeat the code that is executed in all of your sequence structures.  As an example, I have attached a for loop vi that duplicates every frame in your sequence that writes to the serial port.  Instead of having all those frames, I have one loop.  Study the attached vi, modify your vi to look similar, then post any more questions you might have.  Try to get rid of all sequence structures, you don't need them for this program.  Event the Forward, Reverse code can be done in a loop.  If you don't know what loops are, you should study any examples tha come with Labview.

Also, your boolean array has only one dimension.  It contains an array of bits.  To show each byte, you need a two dimensional array.  My example shows how each byte is stored in the 2D array.  The first value (4 bit array) is in row 0, the second in row 1, etc.

- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 15
(4,352 Views)

Hi,

I'm agreed with bob, but if I want to focus on the problem you issued, I suggest using the History property of your waveform chart. (I'm not sure if your questions is related to what I'm saying!)

right click the chart in block diagram and create a property node. then select History. you'll have your array.

 

0 Kudos
Message 6 of 15
(4,350 Views)
I have also modified your vi to use a state machine architecture. I have not looked at tbob's code yet. I was finishing this just as he posted his. I agree that sequence structures should be avoided. I used only one because your subVI did not have error clusters to control the order of execution by dataflow.

Lynn
Message 7 of 15
(4,346 Views)
Sorry. Hit the submit button before the Choose file.

Lynn
0 Kudos
Message 8 of 15
(4,345 Views)
Lynn:  You forgot to attach your vi.  Also, my vi has a broken arrow because it isn't complete.  I just wanted to show an example of how a loop could replace all those frames.  The input array is probably not in the correct order or not the correct values.  Again, this is just an example.
- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 15
(4,200 Views)
I must have sent the previous post just as Lynn was sending her attachment.  Very nice job, Lynn.  Notice how this vi is so much easier to read and understand, and how it eliminates having to duplicate so much code.  State machines are great.
- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 15
(4,189 Views)