Jump to content

Conditional structures: Difference between revisions

no edit summary
No edit summary
Line 551:
match [op, _] { throw(`unknown operator: $op`) }
}</lang>
 
=={{header|Efene}}==
 
the expressions can contain parenthesis or not, here both options are shown
 
since if and case do pattern matching if an if or case expression don't match some of the patterns the program will crash
 
===if-elseif-else===
 
<lang efene>
# with parentheses
 
# this will crash if condition1 is not true
# always a condition must match
if (condition1) {
# do something if condition1 is true
}
 
if (condition1) {
# do something if condition1 is true
} else {
# do something if condition1 is false
}
 
if (condition1) {
# do something if condition1 is true
} (condition2) {
# do something if condition2 is true
} else {
# do something if condition1 is false
}
 
# without parentheses
 
# this will crash if condition1 is not true
# always a condition must match
if condition1 {
# do something if condition1 is true
}
 
if condition1 {
# do something if condition1 is true
} else {
# do something if condition1 is false
}
 
if condition1 {
# do something if condition1 is true
} condition2 {
# do something if condition2 is true
} else {
# do something if condition1 is false
}
</lang>
 
===switch===
 
<lang efene> # with parenthesis
 
switch (Value) {
(1) {
# do something if value is 1
} (2) {
# do something if value is 2
} (3) {
# do something if value is 3
}
} else {
# do something if no other case matched
}
 
# with parenthesis
 
switch Value {
1 {
# do something if value is 1
} 2 {
# do something if value is 2
} 3 {
# do something if value is 3
}
} else {
# do something if no other case matched
}</lang>
 
=={{header|FALSE}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.