<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../style.css">
<title>
Gambas Documentation - FOR
</title>
</head>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help+en"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../lang+en">Up</a>&nbsp;
<a href="flush+en">Previous</a>&nbsp;
<a href="foreach+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
FOR
</h1>
<div class="black"><font size="-2"><b>Syntax</b></font></div>
<pre class="syntax"><b>FOR</b> <u>Variable</u> <b>=</b> <u>Expression</u> <b>TO</b> <u>Expression</u> [ <b>STEP</b> <u>Expression</u> ]
&nbsp;&nbsp;&nbsp;...
<b>NEXT</b></pre><p>

Repeats a loop while incrementing or decrementing a variable.
<p>
Note that the variable must be:
<p>
<ul>
<li>Numeric, i.e. a <a href="type/byte+en">Byte</a>, a <a href="type/short+en">Short</a>, an <a href="type/integer+en">Integer</a>, a <a href="type/long+en">Long</a> or a <a href="type/float+en">Float</a> number.
<li>A local variable.
<p>
</ul>

Note that if the initial expression is higher than the final expression (for positive <a href="step+en">STEP</a> values), or if the initial expression is less than the final expression (for negative ones) the loop will not be executed at all.
<p>
<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">DIM iCount AS Integer

FOR iCount = 1 TO 20 STEP 3
  PRINT iCount & &quot; &quot;;
NEXT
<hr>1 4 7 10 13 16 19</pre>
<p>
<hr><b>See also</b><br>
<a href="../cat/loop+en">Loop Control Structures</a>&nbsp;

</div>
</body>
</html>

