<!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 - IF
</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="hyp+en">Previous</a>&nbsp;
<a href="iif+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
IF
</h1>
<div class="black"><font size="-2"><b>Syntax</b></font></div>
<pre class="syntax"><b>IF</b> <u>Expression</u> [ { <b>AND IF</b> | <b>OR IF</b> } <u>Expression</u> ... ] <b>THEN</b>
&nbsp;&nbsp;...
[ <b>ELSE IF</b> <u>Expression</u> [ { <b>AND IF</b> | <b>OR IF</b> } <u>Expression</u> ... ] <b>THEN</b>
&nbsp;&nbsp;... ]
[ <b>ELSE</b>
&nbsp;&nbsp;... ]
<b>ENDIF</b></pre><p>

Conditional control structure.
<p>
When you use several test expressions splitted by <tt><b>AND IF</b></tt> keywords, then they are evaluated from left to right until the first <a href="false+en">FALSE</a> one is found, and then the test is <a href="false+en">FALSE</a>. If all expressions are <a href="true+en">TRUE</a>, then the test is <a href="true+en">TRUE</a>.
<p>
When you use several test expressions splitted by <tt><b>OR IF</b></tt> keywords, then they are evaluated from left to right until the first <a href="true+en">TRUE</a> one is found, and then the test is <a href="true+en">TRUE</a>. If all expressions are <a href="false+en">FALSE</a>, then the test is <a href="false+en">FALSE</a>.
<p>
<div class="warning"><table class="none" border="0"><tr><td width="40" valign="top"><img border="0" src="../../img/info.png" align="center"></td><td valign="top">
You cannot mix <tt><b>AND IF</b></tt> and <tt><b>OR IF</b></tt> keywords on the same line.
</td></tr></table></div>
<p>
<div class="gray"><font size="-2"><b>Example</b></font></div>
<pre class="example">DIM k AS Integer

FOR k = 1 TO 10

  IF k < 5 OR IF k > 5 THEN
    PRINT k;;
  ELSE
    PRINT
    PRINT &quot;5 has been reached!&quot;
  END IF

NEXT

PRINT
<hr>1 2 3 4
5 has been reached!
6 7 8 9 10</pre>
<p>
<hr><b>See also</b><br>
<a href="../cat/test+en">Test Control Structures &amp; Functions</a>&nbsp;

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

