Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In most computer programming languages, a while loop is a <a href="http://en.wikipedia.org/wiki/Control_flow" rel="nofollow">control flow</a> <a href="http://en.wikipedia.org/wiki/Statement_%28programming%29" rel="nofollow">statement</a> that allows code to be executed repeatedly based on a given <a href="http://en.wikipedia.org/wiki/Boolean_datatype" rel="nofollow">boolean</a> condition. The while loop can be thought of as a repeating <a href="http://en.wikipedia.org/wiki/Conditional_%28programming%29" rel="nofollow">if statement</a>.</p> <p>The while construct consists of a block of code and a condition. The condition is evaluated, and if the condition is true, the code within the block is executed. This repeats until the condition becomes false. Because the while loop checks the condition before the block is executed, the control structure is often also known as a pre-test loop. Compare this with the <em>do-while</em> loop, which tests the condition after the loop has executed.</p> <p>The syntax for the while loop for many computer languages is as follows:</p> <pre><code>while (true) { //do complicated stuff if (someCondition) break; //more stuff } </code></pre> <p>(excerpted from <a href="http://en.wikipedia.org/wiki/While_loop" rel="nofollow">http://en.wikipedia.org/wiki/While_loop</a>, with minor changes)</p> <p>There are several types of different while loops in modern computing. One of these loops is called a sentinel loop. This loop will run until a "sentinel" value is hit. An example follows in <strong>pseudo code</strong> (this example is a simple accumulator):</p> <pre><code>Initialize a data type to not the sentinel value while(data!=(sentinel value)){ do something ask for more data (which will be put into the data variable) } </code></pre> <p>See also: <a href="/questions/tagged/loops" class="post-tag" title="show questions tagged &#39;loops&#39;" rel="tag">loops</a>, <a href="/questions/tagged/foreach" class="post-tag" title="show questions tagged &#39;foreach&#39;" rel="tag">foreach</a>, <a href="/questions/tagged/for-loop" class="post-tag" title="show questions tagged &#39;for-loop&#39;" rel="tag">for-loop</a>, and <a href="/questions/tagged/do-while" class="post-tag" title="show questions tagged &#39;do-while&#39;" rel="tag">do-while</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload