<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="None">
  <name>While Loops</name>
  <metadata>
  <md:version>1.1</md:version>
  <md:created>2004/06/15 15:19:16 GMT-5</md:created>
  <md:revised>2004/07/16 15:03:36.178 GMT-5</md:revised>
  <md:authorlist>
      <md:author id="NationalInstruments">
      <md:firstname>National</md:firstname>
      
      <md:surname>Instruments</md:surname>
      <md:email>certification@ni.com</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="NationalInstruments">
      <md:firstname>National</md:firstname>
      
      <md:surname>Instruments</md:surname>
      <md:email>certification@ni.com</md:email>
    </md:maintainer>
    <md:maintainer id="harika">
      <md:firstname>Harika</md:firstname>
      
      <md:surname>Basana</md:surname>
      <md:email>ilsai@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="mshiralkar05">
      <md:firstname>Malan</md:firstname>
      
      <md:surname>Shiralkar</md:surname>
      <md:email>mshiralkar05@hotmail.com</md:email>
    </md:maintainer>
    <md:maintainer id="lizzardg">
      <md:firstname>Elizabeth</md:firstname>
      
      <md:surname>Gregory</md:surname>
      <md:email>lizzardg@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  

  <md:abstract/>
</metadata>
  
  <content>
    
    <para id="p1">
      A <code>While Loop</code> executes a subdiagram until a
      condition is met. The <code>While Loop</code> is similar to a
      <code>Do Loop</code> or a <code>Repeat-Until Loop</code> in
      text-based programming. <cnxn target="troy"/> shows a
      <code>While Loop</code> in LabVIEW, a flow chart equivalent of
      the <code>While Loop</code> functionality, and a pseudo code
      example of the functionality of the <code>While Loop</code>.
      <figure id="troy">
	<media type="image/png" src="WhileLooptheory.png"/>
      </figure>
    </para>
    
    <para id="p2">
      The <code>While Loop</code> is located on the
      <code>Functions&gt;&gt;Execution Control </code> palette. Select the
      <code>While Loop</code> from the palette then use the cursor to
      drag a selection rectangle around the section of the block
      diagram you want to repeat. When you release the mouse button, a
      <code>While Loop</code> boundary encloses the section you
      selected.
    </para>
    
    <para id="p3">
      Add block diagram objects to the <code>While Loop</code> by
      dragging and dropping them inside the <code>While Loop</code>.
      <note>
	The <code>While Loop</code> always executes at least once.
      </note>
    </para>
    
    <para id="p4">
      <media id="m1" type="image/png" src="stopiftrue.png"/> The
      <code>While Loop</code> executes the subdiagram until the
      conditional terminal, an input terminal, receives a specific
      Boolean value. The default behavior and appearance of the
      conditional terminal is <code>Stop If True</code>, shown in
      <cnxn target="m1"/>. When a conditional terminal is <code>Stop
	If True</code>, the <code>While Loop</code> executes its
      subdiagram until the conditional terminal receives a
      <code>True</code> value.
    </para>
    
    <para id="p5">
      <media id="m2" type="image/png" src="iteration.png"/> The
      <code>iteration</code> terminal, an output terminal, shown in
      <cnxn target="m2"/>, contains the number of completed
      iterations. The iteration count always starts at zero. During
      the first iteration, the iteration terminal returns
      <code>0</code>.
    </para>
    
    <para id="p6"> 
      In the block diagram in <cnxn target="tree"/>, the <code>While
	Loop</code> executes until the subVI output is greater than or
      equal to <code>10.00</code> and the <code>Enable</code> control
      is <code>True</code>. The <code>And</code> function returns
      <code>True</code> only if both inputs are
      <code>True</code>. Otherwise, it returns <code>False</code>.
      <figure id="tree">
	<media type="image/png" src="stoptrueex.png"/>
      </figure>
    </para>
    
    <para id="p7">
      In the <cnxn target="tree">previous example</cnxn>, there is an
      increased probability of an infinite loop. Generally, the
      desired behavior is to have one condition met to stop the loop,
      rather than requiring both conditions to be met.
    </para>
    
    <para id="p8">
      <media type="image/png" src="continueiftrue.png"/> You can
      change the behavior and appearance of the conditional terminal
      by right-clicking the terminal or the border of the <code>While
	Loop</code> and selecting <code>Continue if True</code>, shown
      at left. You also can use the <code>Operating</code> tool to
      click the conditional terminal to change the condition. When a
      conditional terminal is <code>Continue if True</code>, the
      <code>While Loop</code> executes its subdiagram until the
      conditional terminal receives a <code>False</code> value, as
      shown in <cnxn target="tre"/>.
      <figure id="tre">
	<media type="image/png" src="conttrueex.png"/>
      </figure>
    </para>
    
    <para id="p9">
      The <code>While Loop</code> executes until the subVI output is
      less than <code>10.00</code> or the <code>Enable</code> control
      is <code>False</code>.
    </para>
    
    <section>
      <name>Structure Tunnels</name>
      <para id="se29">
	Data can be passed out of or into a <code>While Loop</code>
	through a tunnel. Tunnels feed data into and out of
	structures. The tunnel appears as a solid block on the border
	of the <code>While Loop</code>. The block is the color of the
	data type wired to the tunnel. Data pass out of a loop after
	the loop terminates. When a tunnel passes data into a loop,
	the loop executes only after data arrive at the tunnel.
      </para>
      
      <para id="se26">
	In <cnxn target="t33ee"/>, the <code>iteration</code> terminal
	is connected to a tunnel. The value in the tunnel does not get
	passed to the <code>Iteration Number</code> indicator until
	the <code>While Loop</code> has finished execution.
	<figure id="t33ee">
	  <media type="image/png" src="tunnelex.png"/>
	</figure>
      </para>
      
      <para id="se23">
	Only the last value of the iteration terminal displays in the
	<code>Iteration Number</code> indicator.
      </para>
    </section>
  </content>
</document>
