IF-THEN-ELSE-END IF/de
(→Anmerkungen) |
(→Beispiel) |
||
Line 100: | Line 100: | ||
Dim A As Integer | Dim A As Integer | ||
A = 10 | A = 10 | ||
− | If A = 10 Then | + | If A = 10 Then 'test expression |
− | Print " | + | Print "This part is executed." 'this will be printed |
Else | Else | ||
+ | Print "This will never be executed." 'this not | ||
+ | End If | ||
+ | If A = 10 Then Print "New in BASCOM" | ||
+ | If A = 10 Then Goto Label1 Else print "A<>10" | ||
+ | Label1: | ||
+ | |||
+ | Rem The following example shows enhanced use of IF THEN | ||
+ | If A.15 = 1 Then 'test for bit | ||
+ | Print "BIT 15 IS SET" | ||
+ | EndIf | ||
+ | Rem the following example shows the 1 line use of IF THEN [ELSE] | ||
+ | If A.15 = 0 Then Print "BIT 15 is cleared" Else Print "BIT 15 is set" | ||
</source><br/>{{Languages}} | </source><br/>{{Languages}} | ||
[[Category:BASCOM Language Reference/de]] | [[Category:BASCOM Language Reference/de]] |
Revision as of 00:06, 21 February 2013
Contents |
Funktion
Erlaubt die bedingte Ausführung bzw. Verzweigung in Abhängigkeit von einer Bedingung.
Syntax
IF expression THEN
[ ELSEIF expression THEN ]
[ ELSE ]
END IF
Anmerkungen
Expression |
Beliebiger Ausdruck der zu Wahr oder Falsch ausgewertet werden kann. |
Einzeilenversion :
IF expression THEN statement [ ELSE statement ]
Die Verwendung von [ELSE] ist optional.
Bedingungen bei IF THEN können auch Bits und Bit Indizes verwenden.
IF var.bit = 1 THEN
^--- bit ist eine Variable oder numerische Konstante im Bereich 0-255
Man kann OR oder AND benutzen um Mehrfachbedingungen zu konstruieren. Die Bedingungen werden von links nach rechts ausgewertet.
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 ist 1"
EndIf
Siehe auch
Beispiel
Dim A As Integer A = 10 If A = 10 Then 'test expression Print "This part is executed." 'this will be printed Else Print "This will never be executed." 'this not End If If A = 10 Then Print "New in BASCOM" If A = 10 Then Goto Label1 Else print "A<>10" Label1: Rem The following example shows enhanced use of IF THEN If A.15 = 1 Then 'test for bit Print "BIT 15 IS SET" EndIf Rem the following example shows the 1 line use of IF THEN [ELSE] If A.15 = 0 Then Print "BIT 15 is cleared" Else Print "BIT 15 is set"
Languages | English • Deutsch |
---|