Conditional structures: Difference between revisions
Content added Content deleted
(Added Deluge.) |
(Add Seed7 example) |
||
Line 2,720: | Line 2,720: | ||
<lang>composite |
<lang>composite |
||
consonant</lang> |
consonant</lang> |
||
⚫ | |||
=={{header|Seed7}}== |
|||
⚫ | |||
⚫ | |||
There can be single or multiple statements. An if-statement can have multiple elsif parts. |
|||
<lang seed7>if condition then |
|||
statement |
|||
⚫ | |||
if condition then |
|||
statement1 |
|||
⚫ | |||
statement2; |
|||
end if; |
|||
if condition1 then |
|||
statement1 |
|||
elsif condition2 then |
|||
statement2; |
|||
end if; |
|||
if condition1 then |
|||
statement1 |
|||
elsif condition2 then |
|||
statement2; |
|||
else |
|||
statement3; |
|||
end if;</lang> |
|||
=== case === |
|||
<lang seed7>case i of |
|||
when {1, 4, 9}: # Executed if i is 1, 4 or 9 |
|||
statement1; |
|||
when {11} | {13 .. 17}: # Executed if i is 11, 13, 14, 15, 16 or 17 |
|||
statement2; |
|||
when {42}: # Executed only if i is 42 |
|||
statement3; |
|||
otherwise: |
|||
statement4; |
|||
end case;</lang> |
|||
⚫ | |||
===if-else if-else=== |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
else |
|||
⚫ | |||
end if</lang> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
<lang slate>"Conditionals in Slate are really messages sent to Boolean objects. Like Smalltalk. (But the compiler might optimize some cases)" |
<lang slate>"Conditionals in Slate are really messages sent to Boolean objects. Like Smalltalk. (But the compiler might optimize some cases)" |
||
balance > 0 |
balance > 0 |
||
Line 2,731: | Line 2,782: | ||
===caseOf:otherwise:=== |
===caseOf:otherwise:=== |
||
<lang slate>c@(Net URLPathEncoder traits) convert |
<lang slate>c@(Net URLPathEncoder traits) convert |
||
[ | byte1 byte2 byte3 digit1 digit2| |
[ | byte1 byte2 byte3 digit1 digit2| |
||
Line 2,751: | Line 2,801: | ||
<lang slate>[p isAtEnd] whileFalse: [p next evaluate]].</lang> |
<lang slate>[p isAtEnd] whileFalse: [p next evaluate]].</lang> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |