Example Code

While Loop Problem

Code and Documents

Attachment

block diagram.jpg

I have a problem related to the while loop of LabVIEW. When the loop termination condition is satisfied, there is an extra iteration performed in the loop. And the final result obtained from the loop is achieved in the extra iteration. The following is the block diagram of my code. Can anyone help me with this? Thanks a lot.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
tstahl
Member
Member
on

The iteration counter of the while loop is zero indexed, so it starts at 0 and not 1.  I expect this is the source of your problem.

Michael0615
Member
Member
on

Thanks for your comments! But it is not the problem since my loop is expected to stop within the maximum number of iterations. As a result, it is not that relevant to the iteration counter of the while loop.

tstahl
Member
Member
on

To verify... if you put a number of iterations of 1, this while loop will execute two times the way it is written.  This is what you want?

Tim

Michael0615
Member
Member
on

Hello Tim,

That is not exactly what I meant. What my problem is that when the termination condition of my loop is satisfied, there is an extra iteration taken place in the loop, and then the whole loop stops.

tstahl
Member
Member
on

I think you're describing the proper operation of the while loop.  The condition is checked after the loop has executed.

Michael0615
Member
Member
on

Yes, that is the point. At the moment, I have already fixed the problem. Thanks a lot.

Contributors