IF-THEN-ELSE-END IF/de
(→(**COPIED FROM ENGLISH PAGE**) =) |
(→Beispiel) |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 27: | Line 27: | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | = <span class="f_Header"> | + | = <span class="f_Header">Anmerkungen</span> = |
<div style="padding: 0px; margin: 0px 0px 0px 4px;"> | <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;" | {| width="541" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;" | ||
Line 35: | Line 35: | ||
| valign="top" width="100%" style="width: 444px; border: 1px solid rgb(0, 0, 0);" | | | valign="top" width="100%" style="width: 444px; border: 1px solid rgb(0, 0, 0);" | | ||
− | + | Beliebiger Ausdruck der zu Wahr oder Falsch ausgewertet werden kann. | |
|} | |} | ||
Line 43: | Line 43: | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | + | Einzeilenversion : | |
IF expression THEN statement [ ELSE statement ] | IF expression THEN statement [ ELSE statement ] | ||
− | + | Die Verwendung von [ELSE] ist optional. | |
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | + | Bedingungen bei IF THEN können auch Bits und Bit Indizes verwenden. | |
IF var.bit = 1 THEN | IF var.bit = 1 THEN | ||
− | ^--- bit | + | ^--- 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 OR A=2 OR A=3 OR B>10 THEN | ||
Line 79: | Line 79: | ||
If Var.idx = 1 Then | If Var.idx = 1 Then | ||
− | Print "Bit 1 | + | Print "Bit 1 ist 1" |
EndIf | EndIf | ||
Line 87: | Line 87: | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | = <span class="f_Header"> | + | = <span class="f_Header">Siehe auch</span> = |
[[ELSE]] | [[ELSE]] | ||
Line 95: | Line 95: | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | = <span class="f_Header"> | + | = <span class="f_Header">Beispiel</span> = |
<br/><source lang="bascomavr"> | <br/><source lang="bascomavr"> | ||
Dim A As Integer | Dim A As Integer | ||
A = 10 | A = 10 | ||
− | If A = 10 Then | + | If A = 10 Then 'Bedingung |
− | Print " | + | Print "Dieser Teil wird ausgeführt." 'Dieses wird ausgegeben |
Else | Else | ||
+ | Print "Dieses wird nie ausgeführt." 'dieses nicht | ||
+ | End If | ||
+ | If A = 10 Then Print "Neu in BASCOM" | ||
+ | If A = 10 Then Goto Label1 Else print "A<>10" | ||
+ | Label1: | ||
+ | |||
+ | Rem Das folgende Beispiel zeigt eine erweiterte Benutzung von IF THEN | ||
+ | If A.15 = 1 Then 'Ein Bit testen | ||
+ | Print "BIT 15 ist gesetzt" | ||
+ | EndIf | ||
+ | Rem Das folgende Beispiel zeigt die Einzeilen-Nutzung von IF THEN [ELSE] | ||
+ | If A.15 = 0 Then Print "BIT 15 ist Null" Else Print "BIT 15 ist gesetzt" | ||
</source><br/>{{Languages}} | </source><br/>{{Languages}} | ||
[[Category:BASCOM Language Reference/de]] | [[Category:BASCOM Language Reference/de]] |
Latest revision as of 00:22, 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 'Bedingung Print "Dieser Teil wird ausgeführt." 'Dieses wird ausgegeben Else Print "Dieses wird nie ausgeführt." 'dieses nicht End If If A = 10 Then Print "Neu in BASCOM" If A = 10 Then Goto Label1 Else print "A<>10" Label1: Rem Das folgende Beispiel zeigt eine erweiterte Benutzung von IF THEN If A.15 = 1 Then 'Ein Bit testen Print "BIT 15 ist gesetzt" EndIf Rem Das folgende Beispiel zeigt die Einzeilen-Nutzung von IF THEN [ELSE] If A.15 = 0 Then Print "BIT 15 ist Null" Else Print "BIT 15 ist gesetzt"
Languages | English • Deutsch |
---|