Bounded Iteration in Graphical Programs

Bounded iteration in graphical programs lets you repeat a calculation a specified number of times and display the resulting samples together. In LabVIEW, a For Loop provides the repetition, an indexing output tunnel collects the results, and a waveform graph displays them on a uniformly spaced horizontal axis. This pattern is useful when you generate a finite simulated signal or process a known collection of measurements.

Set the repetition bound

Bounded iteration is repetition with an upper limit on the number of executions. For a basic For Loop, wire a nonnegative integer to the count terminal NN. Assume here that the loop has no early-stop condition. Without indexing input arrays, the loop executes NN times.


The iteration terminal ii uses zero-based numbering:


i=0,1,…,N−1i=0,1,\ldots,N-1


Consequently, the last iteration number is one less than the number of executions. If N=0N=0, the loop body does not execute, so there is no last iteration.


An indexing input tunnel supplies one array element per iteration. When several indexing arrays enter the loop, their lengths also limit the count. With NN wired and indexing input lengths L1,L2,…L_1,L_2,\ldots, the effective count is


M=min⁡(N,L1,L2,…)M=\min(N,L_1,L_2,\ldots)


If NN is unwired, indexing input arrays can determine the count from their shortest length. An array passed through a non-indexing input tunnel does not impose this element-by-element limit.

Collect one result per iteration

Auto-indexing is a tunnel behavior that either selects successive input elements or collects successive output values. To build a signal, compute one scalar value yiy_i inside the loop and enable indexing on its output tunnel. Ordinary output indexing collects every iteration's scalar into a one-dimensional array in iteration order.


Output tunnel setting

Result after a nonempty loop

Suitable for retaining every scalar sample?

Indexing enabled

Array containing one value per iteration

Yes

Indexing disabled

Scalar from the final iteration

No


The tunnel setting determines what crosses the loop boundary. Changing a graph's appearance cannot recover samples that a non-indexing tunnel did not retain.


A schematic connects a For Loop through an indexing output tunnel and a timing bundle to a waveform graph.



Give the samples a meaningful horizontal axis

A waveform graph represents samples at equal horizontal intervals. A numeric array wired directly to a graph with default horizontal scaling is plotted at 0,1,2,…0,1,2,\ldots. Those coordinates are sample indices; naming the axis Time does not supply a sampling interval.


For numeric time coordinates, bundle an initial horizontal value x0x_0, a spacing Δx\Delta x, and the array YY. When the horizontal quantity is time, use x0=t0x_0=t_0 and Δx=Δt\Delta x=\Delta t. Sample ii then has time


ti=t0+iΔtt_i=t_0+i\Delta t


For MM samples, where M≥1M\geq1, the final time and the first-to-last span are


tlast=t0+(M−1)Δt,Tspan=(M−1)Δtt_{\text{last}}=t_0+(M-1)\Delta t, \qquad T_{\text{span}}=(M-1)\Delta t


For example, five samples separated by 0.030 s0.030\ \text{s} span 4(0.030)=0.120 s4(0.030)=0.120\ \text{s}. There are four intervals between five points.



Place the graph outside the loop and supply the collected array after completion. Check the output length, first sample, and last sample against your intended time range.


What to remember

  • NN counts executions; ii starts at zero.
  • Indexing inputs can reduce the effective count.
  • An indexing output retains every scalar result.
  • MM uniformly spaced samples span M−1M-1 intervals.

Example: Generate a finite displacement signal

You are preparing a simulated motion signal to test a display before connecting any hardware. The displacement model is


y(t)=0.015 m+(0.250 m/s)ty(t)=0.015\ \text{m}+(0.250\ \text{m/s})t


Generate samples from t=0.000 st=0.000\ \text{s} through t=0.400 st=0.400\ \text{s}, including both endpoints, with spacing Δt=0.080 s\Delta t=0.080\ \text{s}. Use a LabVIEW For Loop with no indexing input arrays and no early stopping, then display the complete result on a waveform graph outside the loop.


Report times and displacements to three decimal places.


A sampling timeline marks the start, one sample interval, and the final requested time.


a) Determine the required count NN and the iteration numbers used.


Divide the requested time span by the spacing to count intervals. Since both endpoints are included, add one to obtain the number of sample points.


Tspan=0.400 s−0.000 s=0.400 sIntervals=0.400 s0.080 s=5N=5+1=6\begin{aligned} T_{\text{span}}&=0.400\ \text{s}-0.000\ \text{s}=0.400\ \text{s}\\ \text{Intervals}&=\frac{0.400\ \text{s}}{0.080\ \text{s}}=5\\ N&=5+1=6 \end{aligned}


Wire 6 to the count terminal. The six iteration numbers are i=0,1,2,3,4,5i=0,1,2,3,4,5. The last iteration number is 5, which agrees with the ________ intervals between the endpoints.


b) Calculate the time and displacement at every iteration, and state how to retain the full output array.


Inside the loop, convert the dimensionless iteration number into a time, then evaluate the displacement model. Each multiplication of velocity by time gives a displacement in metres.


ti=i(0.080 s),yi=0.015 m+(0.250 m/s)tit_i=i(0.080\ \text{s}), \qquad y_i=0.015\ \text{m}+(0.250\ \text{m/s})t_i


Substitute each iteration number into these expressions:

  • At i=0i=0, t0=0(0.080 s)=0.000 st_0=0(0.080\ \text{s})=0.000\ \text{s} and y0=0.015 m+(0.250 m/s)(0.000 s)=0.015 my_0=0.015\ \text{m}+(0.250\ \text{m/s})(0.000\ \text{s})=0.015\ \text{m}.
  • At i=1i=1, t1=1(0.080 s)=0.080 st_1=1(0.080\ \text{s})=0.080\ \text{s} and y1=0.015 m+(0.250 m/s)(0.080 s)=0.035 my_1=0.015\ \text{m}+(0.250\ \text{m/s})(0.080\ \text{s})=0.035\ \text{m}.
  • At i=2i=2, t2=2(0.080 s)=0.160 st_2=2(0.080\ \text{s})=0.160\ \text{s} and y2=0.015 m+(0.250 m/s)(0.160 s)=0.055 my_2=0.015\ \text{m}+(0.250\ \text{m/s})(0.160\ \text{s})=0.055\ \text{m}.
  • At i=3i=3, t3=3(0.080 s)=0.240 st_3=3(0.080\ \text{s})=0.240\ \text{s} and y3=0.015 m+(0.250 m/s)(0.240 s)=0.075 my_3=0.015\ \text{m}+(0.250\ \text{m/s})(0.240\ \text{s})=0.075\ \text{m}.
  • At i=4i=4, t4=4(0.080 s)=0.320 st_4=4(0.080\ \text{s})=0.320\ \text{s} and y4=0.015 m+(0.250 m/s)(0.320 s)=0.095 my_4=0.015\ \text{m}+(0.250\ \text{m/s})(0.320\ \text{s})=0.095\ \text{m}.
  • At i=5i=5, t5=5(0.080 s)=0.400 st_5=5(0.080\ \text{s})=0.400\ \text{s} and y5=0.015 m+(0.250 m/s)(0.400 s)=0.115 my_5=0.015\ \text{m}+(0.250\ \text{m/s})(0.400\ \text{s})=0.115\ \text{m}.

Use numeric constants expressed in seconds, metres, and metres per second consistently. Wire the scalar displacement calculation to an output tunnel with ordinary indexing enabled. It collects the six values in iteration order:


Y=[0.015,0.035,0.055,0.075,0.095,0.115] mY=[0.015,0.035,0.055,0.075,0.095,0.115]\ \text{m}


The displacement increment is constant:


Δy=(0.250 m/s)(0.080 s)=0.020 m\Delta y=(0.250\ \text{m/s})(0.080\ \text{s})=0.020\ \text{m}


Every adjacent pair in the array differs by this amount, providing a useful arithmetic check.


c) Specify the graph input and verify the final plotted point.


Outside the loop, use Bundle to form the numeric cluster (x0,Δx,Y)(x_0,\Delta x,Y). Set x0=0.000 sx_0=0.000\ \text{s} and Δx=0.080 s\Delta x=0.080\ \text{s}, and supply the collected displacement array as YY. Wire that cluster to the waveform graph and label its axes Time (s) and Displacement (m).


The final array index is N−1=5N-1=5, so its graph coordinate is


tlast=x0+(N−1)Δx=0.000 s+5(0.080 s)=0.400 s\begin{aligned} t_{\text{last}}&=x_0+(N-1)\Delta x\\ &=0.000\ \text{s}+5(0.080\ \text{s})\\ &=0.400\ \text{s} \end{aligned}


Its displacement is


ylast=0.015 m+(0.250 m/s)(0.400 s)=0.115 my_{\text{last}}=0.015\ \text{m}+(0.250\ \text{m/s})(0.400\ \text{s})=0.115\ \text{m}


The final plotted point is therefore (0.400 s,0.115 m)(0.400\ \text{s},0.115\ \text{m}). Supplying only the array with default graph scaling would instead place its final value at horizontal coordinate ________. The timing cluster assigns the intended physical coordinates; it does not control how long the simulation takes to execute.

A LabVIEW For Loop generates 12 simulated sensor readings. Its count terminal is wired to N=12N=12, it has no indexing input arrays, and early stopping is disabled. Which sequence of values appears at its iteration terminal ii?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

On two separate runs of a LabVIEW program, a For Loop produces a complete voltage array. After each loop finishes, its array is written directly to the same single-plot Waveform Graph.


The first run writes [1,2,3,4][1,2,3,4] V. The second run writes [−2,0,2][-2,0,2] V. No other code stores or combines the arrays.


After the second write, the graph displays points, and the first point has a y value of V.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A LabVIEW For Loop generates 81 voltage samples, one per iteration, and retains all of them through an indexing output tunnel. The loop has no indexing inputs or early stopping. A waveform graph receives the cluster (x0,Δx,Y)(x_0,\Delta x,Y) with x0=1.200 sx_0=1.200\ \text{s} and Δx=0.025 s\Delta x=0.025\ \text{s}. What is the time coordinate of the final sample? Answer in seconds, to three decimal places.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice