| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
| 2 |
"http://www.w3.org/TR/html4/strict.dtd"> |
| 3 |
<html> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| 6 |
<title>if, then, elseif, else, endif</title> |
| 7 |
<meta http-equiv="Content-Style-Type" content="text/css"> |
| 8 |
<link rel="stylesheet" href="../../style.css" type="text/css"> |
| 9 |
</head> |
| 10 |
|
| 11 |
<body> |
| 12 |
|
| 13 |
|
| 14 |
<h1>if, then, elseif, else, endif</h1> |
| 15 |
|
| 16 |
<p> |
| 17 |
Conditional branching |
| 18 |
</p> |
| 19 |
|
| 20 |
<h2>1) Format 1</h2> |
| 21 |
|
| 22 |
<pre class="macro-syntax"> |
| 23 |
if <expression> <statement> |
| 24 |
</pre> |
| 25 |
|
| 26 |
<h3>Remarks</h3> |
| 27 |
|
| 28 |
<p> |
| 29 |
Executes a <statement>, if <expression> is true(non-zero). |
| 30 |
</p> |
| 31 |
|
| 32 |
<h3>Example</h3> |
| 33 |
|
| 34 |
<pre class="macro-example"> |
| 35 |
; If A>1, jump to ':label'. |
| 36 |
if A>1 goto label |
| 37 |
|
| 38 |
; If result<>0, assign 0 to A. |
| 39 |
if result A=0 |
| 40 |
</pre> |
| 41 |
|
| 42 |
|
| 43 |
<h2>2) Format 2</h2> |
| 44 |
|
| 45 |
<pre class="macro-syntax"> |
| 46 |
if <expression 1> then |
| 47 |
... |
| 48 |
(Statements for the case: <expression 1> is true (non-zero).) |
| 49 |
... |
| 50 |
[elseif <expression 2> then] |
| 51 |
... |
| 52 |
(Statements for the case: <expression 1> is false (zero) and <expression 2> is true.) |
| 53 |
... |
| 54 |
[elseif <expression N> then] |
| 55 |
... |
| 56 |
(Statements for the case: <expression 1>, <expression 2>,... and <expression N-1> are all false, and <expression N> is true.) |
| 57 |
... |
| 58 |
[else] |
| 59 |
... |
| 60 |
(Statements for the case: all the conditions above are false (zero).) |
| 61 |
... |
| 62 |
endif |
| 63 |
</pre> |
| 64 |
|
| 65 |
<h3>Remarks</h3> |
| 66 |
|
| 67 |
<p> |
| 68 |
'if' and 'elseif' statements must end with 'then'.<br> |
| 69 |
'elseif' and 'else' can be omitted.<br> |
| 70 |
'endif' can not be omitted. |
| 71 |
</p> |
| 72 |
|
| 73 |
<h3>Example</h3> |
| 74 |
|
| 75 |
<pre class="macro-example"> |
| 76 |
if a=1 then |
| 77 |
b = 1 |
| 78 |
c = 2 |
| 79 |
d = 3 |
| 80 |
endif |
| 81 |
|
| 82 |
if i<0 then |
| 83 |
i=0 |
| 84 |
else |
| 85 |
i=i+1 |
| 86 |
endif |
| 87 |
|
| 88 |
if i=1 then |
| 89 |
c = '1' |
| 90 |
elseif i=2 then |
| 91 |
c = '2' |
| 92 |
elseif i=3 then |
| 93 |
c = '3' |
| 94 |
else |
| 95 |
c = '?' |
| 96 |
endif |
| 97 |
</pre> |
| 98 |
|
| 99 |
|
| 100 |
<h3>*) NOTICE</h3> |
| 101 |
|
| 102 |
<em>(version 4.90 or later)</em><br> |
| 103 |
By using Format 2(if - endif), the syntax error occurs when then is not described. |
| 104 |
|
| 105 |
<pre class="macro-example"> |
| 106 |
code = 100 |
| 107 |
if code != 100 |
| 108 |
messagebox 'The code value is not 100.' 'error' |
| 109 |
goto error |
| 110 |
else |
| 111 |
messagebox 'The code value is 100.' 'OK' |
| 112 |
endif |
| 113 |
|
| 114 |
:error |
| 115 |
end |
| 116 |
</pre> |
| 117 |
|
| 118 |
|
| 119 |
<h2>See also</h2> |
| 120 |
<ul> |
| 121 |
<li><a href="../syntax/expressions.html">Expressions and operators</a></li> |
| 122 |
</ul> |
| 123 |
|
| 124 |
</body> |
| 125 |
</html> |