<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/language.control-structures.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'control-structures.while.php',
    1 => 'while',
    2 => 'while',
  ),
  'up' => 
  array (
    0 => 'language.control-structures.php',
    1 => 'Strutture di controllo',
  ),
  'prev' => 
  array (
    0 => 'control-structures.alternative-syntax.php',
    1 => 'Sintassi alternativa per le strutture di controllo',
  ),
  'next' => 
  array (
    0 => 'control-structures.do.while.php',
    1 => 'do-while',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    'path' => 'language/control-structures/while.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="control-structures.while" class="sect1">
 <h2 class="title"><code class="literal">while</code></h2>
 <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p>
 <p class="para">
  I cicli <code class="literal">while</code> sono i più semplici tipi di loop in PHP.
  Questi cicli si comportano esattamente come nel C. 
  La forma base di un&#039;istruzione <code class="literal">while</code> è:
  <div class="informalexample">
   <div class="example-contents">
<div class="cdata"><pre>
while (expr)
    statement
</pre></div>
   </div>

  </div>
 </p>
 <p class="simpara">
  The meaning of a <code class="literal">while</code> statement is simple.  It
  tells PHP to execute the nested statement(s) repeatedly, as long
  as the <code class="literal">while</code> expression evaluates to
  <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>.  The value of the expression is checked
  each time at the beginning of the loop, so even if this value
  changes during the execution of the nested statement(s), execution
  will not stop until the end of the iteration (each time PHP runs
  the statements in the loop is one iteration).  Sometimes, if the
  <code class="literal">while</code> expression evaluates to
  <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> from the very beginning, the nested
  statement(s) won&#039;t even be run once.
 </p>
 <p class="para">
  Like with the <code class="literal">if</code> statement, you can group
  multiple statements within the same <code class="literal">while</code> loop
  by surrounding a group of statements with curly braces, or by
  using the alternate syntax:
  <div class="informalexample">
   <div class="example-contents">
<div class="cdata"><pre>
while (expr):
    statement
    ...
endwhile;
</pre></div>
   </div>

  </div>
 </p>
 <p class="para">
  Gli esempi seguenti sono identici, ed entrambi stampano i numeri da 1 a 10:
  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/* example 1 */<br /><br /></span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />while (</span><span style="color: #0000BB">$i </span><span style="color: #007700">&lt;= </span><span style="color: #0000BB">10</span><span style="color: #007700">) {<br />    echo </span><span style="color: #0000BB">$i</span><span style="color: #007700">++;  </span><span style="color: #FF8000">/* the printed value would be<br />                   $i before the increment<br />                   (post-increment) */<br /></span><span style="color: #007700">}<br /><br /></span><span style="color: #FF8000">/* example 2 */<br /><br /></span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />while (</span><span style="color: #0000BB">$i </span><span style="color: #007700">&lt;= </span><span style="color: #0000BB">10</span><span style="color: #007700">):<br />    echo </span><span style="color: #0000BB">$i</span><span style="color: #007700">;<br />    </span><span style="color: #0000BB">$i</span><span style="color: #007700">++;<br />endwhile;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

  </div>
 </p>
</div><?php manual_footer($setup); ?>