From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For loop, possible to increment counter/exit loop?

I would like to know if it is possible to exit a For loop. I know
I can use a while loop but it would be nice to be able to
increment the loop counter in a for loop. Is this possible?

Thanks,
Mike
0 Kudos
Message 1 of 4
(2,943 Views)
Mike Scirocco wrote:

> I would like to know if it is possible to exit a For loop. I know
> I can use a while loop but it would be nice to be able to
> increment the loop counter in a for loop. Is this possible?
>
> Thanks,
> Mike

No sorry it is not possible.
If you need this kind of functionality you will have to use a while loop.
You can then setup all manner of conditions to exit the loop.
Be aware that the loop will always run at least ONCE.

A for loop will run X number of times. This is determined either
at compile time (if the count is hard coded) or at run time
(if you use auto-indexing, or the count is a variable).

Kevin Kent
0 Kudos
Message 2 of 4
(2,943 Views)
Also remember you can make while loops auto index. Right pop on the tunnel
and enable this and the loop will then act more like a for loop.

Jim

"Kevin B. Kent" wrote:

> Mike Scirocco wrote:
>
> > I would like to know if it is possible to exit a For loop. I know
> > I can use a while loop but it would be nice to be able to
> > increment the loop counter in a for loop. Is this possible?
> >
> > Thanks,
> > Mike
>
> No sorry it is not possible.
> If you need this kind of functionality you will have to use a while loop.
> You can then setup all manner of conditions to exit the loop.
> Be aware that the loop will always run at least ONCE.
>
> A for loop will run X number of times. This is determined either
> at compile time (if the count is hard c
oded) or at run time
> (if you use auto-indexing, or the count is a variable).
>
> Kevin Kent
0 Kudos
Message 3 of 4
(2,943 Views)
Jim,

OK, that clears it up. Coming from VB I'm still figuring out the
differences.

Thanks,
Mike

James Morrison/Joan Lester wrote:
>
> Also remember you can make while loops auto index. Right pop on the tunnel
> and enable this and the loop will then act more like a for loop.
>
> Jim
>
> "Kevin B. Kent" wrote:
>
> > Mike Scirocco wrote:
> >
> > > I would like to know if it is possible to exit a For loop. I know
> > > I can use a while loop but it would be nice to be able to
> > > increment the loop counter in a for loop. Is this possible?
> > >
> > > Thanks,
> > > Mike
> >
> > No sorry it is not possible.
> > If you need this kind of functionality you will have to use a while loop.
> > You can then setup all manner of conditions to exit the lo
op.
> > Be aware that the loop will always run at least ONCE.
> >
> > A for loop will run X number of times. This is determined either
> > at compile time (if the count is hard coded) or at run time
> > (if you use auto-indexing, or the count is a variable).
> >
> > Kevin Kent
0 Kudos
Message 4 of 4
(2,941 Views)