LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

goto command in LabVIEW

Hi
I was wondering if there's anything like a "goto" command in labview. For example, if I am in a for loop (and the for loop hasn't reached it's number of time to loop yet) and need to exit the loop and jump to somewhere else in a code because I encounter some error condition. I know I can use a while loop for this if there isn't any goto command, but that's my last choice because it's kinda complicated for a nested loop with many procedures.
Thanks
0 Kudos
Message 1 of 8
(6,008 Views)
Well Irene this cannot be done as you say because you cannot break out of a for loop until it is done. with this said you will have to use a while loop and a condtion to stop the loop if it encounters an error. I would suggest so sort of state machine architecture.

I would start by looking at asome of the examples the ship with labview to look some state diagrams



Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 2 of 8
(6,000 Views)
if you just want to bypass the remaining loops in a for loop when an error happens, then use a case structure around your code inside the loop. Normally if it is an I/O operation (file, daq, etc), it is recommended to use error in and error out in your code.

-Joe
0 Kudos
Message 3 of 8
(5,972 Views)

I too would like to find a way to mimic a "goto" function. 

 

In my program, I have a VI that determines if temperature (T1) is stable to within a certain limit for a certain amount of time. After I've found that it's stable, I need to check if another temperature (T2) is within a certain range of a set temp. If it's not, I need to raise T1 so that T2 will also rise to be within range. Then I need to use the aforementioned VI again to check when T1 is stable again. I wish I could just do something like loop the error cluster wire back on itself, making a sort of "goto" command. Otherwise I need to make a very complicated nested While Loop structure. Perhaps I can figure something out with an Event List. Anyone got any suggestions?

0 Kudos
Message 4 of 8
(5,288 Views)
I think you need a state machine. This will be clean with no nested loops. And no goto.
Message 5 of 8
(5,282 Views)

Have you considered a state machine? The states could be something like T1 Unstable, T1 Stable, Check T2, T1 and T2 OK.  You would also have Initialize, Idle, Wait, and Shutdown states and possibly others well as.  There are Design  Patterns which come with LV and many, many posst on the Forum about state machines.

 

In LabVIEW a state machin is usually implemented as a while loop around a case structure.  The "state" is passed from one iteration to the next via a shift register.

 

Lynn

Message 6 of 8
(5,280 Views)

Thanks, RiversDaddy and johnsold! I'll definitely look into that. 

0 Kudos
Message 7 of 8
(5,275 Views)

@VariableRange wrote:

Thanks, RiversDaddy and johnsold! I'll definitely look into that. 


OR, of course you can enable a conditional for loop.  Right click the for loop and "show conditional terminal"  It will even directly accept the error wire and will exit when true (Error) by default


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 8
(5,262 Views)