IF-THEN-ELSE-END IF

(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
IF-THEN-ELSE-END IF<br/><source lang="bascomavr">
+
= <span class="f_Header">Action</span> =
  
 +
Allows conditional execution or branching, based on the evaluation of a Boolean expression.
 +
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
= <span class="f_Header">Syntax</span> =
 +
 +
<span class="f_Syntax">IF</span>&nbsp;expression<span class="f_Syntax">&nbsp;THEN</span>
 +
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
[&nbsp;<span class="f_Syntax">ELSEIF</span>&nbsp;expression&nbsp;<span class="f_Syntax">THEN</span>&nbsp;]
 +
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
[&nbsp;<span class="f_Syntax">ELSE</span>&nbsp;]
 +
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
<span class="f_Syntax">END IF</span>
 +
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
= <span class="f_Header">Remarks</span> =
 +
<div style="padding: 0px; margin: 0px 0px 0px 4px;">
 +
{| width="541" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;"
 +
|- style="vertical-align: top;"
 +
| valign="top" width="17%" style="width: 88px; border: 1px solid rgb(0, 0, 0);" |
 +
Expression
 +
 +
| valign="top" width="100%" style="width: 444px; border: 1px solid rgb(0, 0, 0);" |
 +
Any expression that evaluates to true or false.
 +
 +
|}
 +
</div>
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
The one line version of IF can be used&nbsp;:
 +
 +
IF expression THEN statement [ ELSE statement ]
 +
 +
The use of [ELSE] is optional.
 +
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
Tests like IF THEN can also be used with bits and bit indexes.
 +
 +
IF var.bit = 1 THEN
 +
 +
&nbsp; &nbsp; &nbsp; &nbsp;^--- bit is a variable or numeric constant in the range from 0-255
 +
 +
&nbsp;
 +
 +
You can use OR or AND to test on multiple conditions. The conditions are evaluated from left to right.
 +
 +
IF A=1 OR A=2 OR A=3 OR B>10 THEN
 +
 +
IF A=1 AND A>3 THEN
 +
 +
&nbsp;
 +
 +
&nbsp;
 +
 +
&nbsp;
 +
 +
Dim Var As Byte, Idx As Byte
 +
 +
Var = 255
 +
 +
Idx = 1
 +
 +
If Var.idx = 1 Then
 +
 +
&nbsp;Print "Bit 1 is 1"
 +
 +
EndIf
 +
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
= <span class="f_Header">See also</span> =
 +
 +
[[ELSE]]
 +
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
<span style="font-family: Arial;">&nbsp;</span>
 +
 +
= <span class="f_Header">Example</span> =
 +
 +
<br/><source lang="bascomavr">
 +
Dim A As Integer
 +
A = 10
 +
If A = 10 Then                                             'test expression
 +
Print "This part is executed."                           'this will be printed
 +
Else
 
</source><br/>{{Languages}}
 
</source><br/>{{Languages}}
  
 
[[Category:BASCOM Language Reference]]
 
[[Category:BASCOM Language Reference]]

Revision as of 20:37, 11 February 2013

Contents

Action

Allows conditional execution or branching, based on the evaluation of a Boolean expression.

 

 

Syntax

IF expression THEN

 

ELSEIF expression THEN ]

 

ELSE ]

 

END IF

 

 

Remarks

Expression

Any expression that evaluates to true or false.

 

 

The one line version of IF can be used :

IF expression THEN statement [ ELSE statement ]

The use of [ELSE] is optional.

 

Tests like IF THEN can also be used with bits and bit indexes.

IF var.bit = 1 THEN

       ^--- bit is a variable or numeric constant in the range from 0-255

 

You can use OR or AND to test on multiple conditions. The conditions are evaluated from left to right.

IF A=1 OR A=2 OR A=3 OR B>10 THEN

IF A=1 AND A>3 THEN

 

 

 

Dim Var As Byte, Idx As Byte

Var = 255

Idx = 1

If Var.idx = 1 Then

 Print "Bit 1 is 1"

EndIf

 

 

See also

ELSE

 

 

Example


Dim A As Integer
A = 10
If A = 10 Then                                             'test expression
Print "This part is executed."                           'this will be printed
Else

Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language