CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
1
Task/Conditional-structures/0DESCRIPTION
Normal file
1
Task/Conditional-structures/0DESCRIPTION
Normal file
|
|
@ -0,0 +1 @@
|
|||
{{Control Structures}}This page lists the conditional structures offered by different programming languages. Common conditional structures are '''if-then-else''' and '''switch'''.
|
||||
2
Task/Conditional-structures/1META.yaml
Normal file
2
Task/Conditional-structures/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Control Structures
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
LDA #10
|
||||
CMP #11
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
BNE ;Branch on Not Equal - branch when the zero flag is set
|
||||
BEQ ;Branch on EQual - branch when the zero flag is set.
|
||||
;The zero flag is set when the result of an operation is zero
|
||||
|
||||
BMI ;Branch on MInus
|
||||
BPL ;Branch on PLus - branch when the sign flag is cleared/set.
|
||||
;The sign flag is set when the result of an instruction is a negative number
|
||||
;and cleared when the result is a positive number
|
||||
|
||||
BVS ;Branch on oVerflow Set
|
||||
BVC ;Branch on oVerflow Cleared - branch when the overflow flag is cleared/set.
|
||||
;The overflow flag is set when the result of an addition/subtraction would
|
||||
;result in a number larger than 127 or smaller than -128
|
||||
|
||||
BCS ;Branch on Carry Set
|
||||
BCC ;Branch on Carry Clear - branch when the carry flag is cleared/set.
|
||||
;The carry flag is set when an addition produced a carry and when
|
||||
;a subtraction produced a borrow and cleared if an addition/subtraction
|
||||
;does not produce a carry/borrow. The carry flag also holds bits
|
||||
;after shifts and rotates.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
LDA #200
|
||||
CMP Variable
|
||||
BEQ #3 ;if equal, skip ahead 3 bytes...
|
||||
CLC ;if unequal, continue executing instructions
|
||||
ADC #1
|
||||
STA OtherVariable ; ...to here.
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
LDX #100
|
||||
Loop: ...do something
|
||||
DEX
|
||||
BNE Loop
|
||||
|
|
@ -0,0 +1 @@
|
|||
if(i<0) i=0; else i=42
|
||||
|
|
@ -0,0 +1 @@
|
|||
i=(i<0? 0: 42)
|
||||
10
Task/Conditional-structures/Ada/conditional-structures-1.ada
Normal file
10
Task/Conditional-structures/Ada/conditional-structures-1.ada
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
type Restricted is range 1..10;
|
||||
My_Var : Restricted;
|
||||
|
||||
if My_Var = 5 then
|
||||
-- do something
|
||||
elsif My_Var > 5 then
|
||||
-- do something
|
||||
else
|
||||
-- do something
|
||||
end if;
|
||||
13
Task/Conditional-structures/Ada/conditional-structures-2.ada
Normal file
13
Task/Conditional-structures/Ada/conditional-structures-2.ada
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
type Days is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
|
||||
Today : Days;
|
||||
|
||||
case Today is
|
||||
when Saturday | Sunday =>
|
||||
null;
|
||||
when Monday =>
|
||||
Compute_Starting_Balance;
|
||||
when Friday =>
|
||||
Compute_Ending_Balance;
|
||||
when others =>
|
||||
Accumulate_Sales;
|
||||
end case;
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
case Today is
|
||||
when Monday =>
|
||||
Compute_Starting_Balance;
|
||||
when Friday =>
|
||||
Compute_Ending_Balance;
|
||||
when Tuesday .. Thursday =>
|
||||
Accumulate_Sales;
|
||||
-- ignore Saturday and Sunday
|
||||
end case;
|
||||
10
Task/Conditional-structures/Ada/conditional-structures-4.ada
Normal file
10
Task/Conditional-structures/Ada/conditional-structures-4.ada
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
case Today is
|
||||
when Saturday | Sunday =>
|
||||
null; -- don't do anything, if Today is Saturday or Sunday
|
||||
when Monday =>
|
||||
Compute_Starting_Balance;
|
||||
when Friday =>
|
||||
Compute_Ending_Balance;
|
||||
when Tuesday .. Thursday =>
|
||||
Accumulate_Sales;
|
||||
end case;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
select
|
||||
accept first_entry;
|
||||
-- do something
|
||||
or accept second_entry;
|
||||
-- do something
|
||||
or terminate;
|
||||
end select;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
select
|
||||
My_Task.Start;
|
||||
or
|
||||
delay Timeout_Period;
|
||||
end select;
|
||||
|
|
@ -0,0 +1 @@
|
|||
var x = loggedin ? sessionid : -1
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
if (value > 40) {
|
||||
println ("OK")
|
||||
} elif (value < 20) {
|
||||
println ("FAILED")
|
||||
} else {
|
||||
println ("RETRY")
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
switch (arg) {
|
||||
case "-d":
|
||||
case "--debug":
|
||||
debug = true
|
||||
break
|
||||
case "-f":
|
||||
force = true
|
||||
break
|
||||
default:
|
||||
throw "Unknown option " + arg
|
||||
}
|
||||
|
||||
switch (value) {
|
||||
case > 40:
|
||||
println ("OK")
|
||||
break
|
||||
case < 20:
|
||||
println ("FAILED")
|
||||
break
|
||||
case in 50..59:
|
||||
println ("WIERD")
|
||||
// fall through
|
||||
default:
|
||||
println ("RETRY")
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
if (c1) {
|
||||
// first condition is true...
|
||||
} elif (c2) {
|
||||
// second condition is true...
|
||||
} elif (c3) {
|
||||
// third condition is true...
|
||||
} else {
|
||||
// none was true...
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
if: condition then: {
|
||||
// condition is true...
|
||||
} else: {
|
||||
// condition is false...
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
condition.ifTrue: { /* condition is true... */ } ifFalse: { /* condition is false... */ }
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
IF condition
|
||||
-> if condition is true...
|
||||
ELSEIF condition2
|
||||
-> else if condition2 is true...
|
||||
ELSE
|
||||
-> if all other conditions are not true...
|
||||
ENDIF
|
||||
|
|
@ -0,0 +1 @@
|
|||
IF condition THEN statement
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
DEF c
|
||||
c := IF condition THEN 78 ELSE 19
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
SELECT var
|
||||
CASE n1
|
||||
-> code
|
||||
CASE n2
|
||||
-> code
|
||||
DEFAULT
|
||||
-> no one of the previous case...
|
||||
ENDSELECT
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
SELECT max_possible_value OF var
|
||||
CASE n1
|
||||
-> code
|
||||
CASE n2 TO n3, n4
|
||||
-> more
|
||||
CASE n5 TO n6, n7 TO n8
|
||||
-> more...
|
||||
DEFAULT
|
||||
-> none of previous ones
|
||||
ENDSELECT
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
if myVar is "ok" then return true
|
||||
|
||||
set i to 0
|
||||
if i is 0 then
|
||||
return "zero"
|
||||
else if i mod 2 is 0 then
|
||||
return "even"
|
||||
else
|
||||
return "odd"
|
||||
end if
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
; if
|
||||
x = 1
|
||||
If x
|
||||
MsgBox, x is %x%
|
||||
Else If x > 1
|
||||
MsgBox, x is %x%
|
||||
Else
|
||||
MsgBox, x is %x%
|
||||
|
||||
; ternary if
|
||||
x = 2
|
||||
y = 1
|
||||
var := x > y ? 2 : 3
|
||||
MsgBox, % var
|
||||
|
||||
; while
|
||||
While (A_Index < 3) {
|
||||
MsgBox, %A_Index% is less than 3
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
10 LET A%=1: REM A HAS A VALUE OF TRUE
|
||||
20 IF A% THEN PRINT "A IS TRUE"
|
||||
30 WE CAN OF COURSE USE EXPRESSIONS
|
||||
40 IF A%<>0 THEN PRINT "A IS TRUE"
|
||||
50 IF NOT(A%) THEN PRINT "A IS FALSE"
|
||||
60 REM SOME VERSIONS OF BASIC PROVIDE AN ELSE KEYWORD
|
||||
70 IF A% THEN PRINT "A IS TRUE" ELSE PRINT "A IS FALSE"
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
IF x = 0 THEN doSomething
|
||||
IF x < 0 THEN doSomething ELSE doOtherThing
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
IF x > 0 AND x < 10 THEN
|
||||
'do stuff
|
||||
ELSE IF x = 0 THEN
|
||||
'do other stuff
|
||||
ELSE
|
||||
'do more stuff
|
||||
END IF
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
IF aNumber THEN
|
||||
'the number is not 0
|
||||
ELSE
|
||||
'the number is 0
|
||||
END IF
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
SELECT CASE expression
|
||||
CASE 1
|
||||
'do stuff
|
||||
CASE 2, 3
|
||||
'do other stuff
|
||||
CASE 3.1 TO 9.9
|
||||
'do this
|
||||
CASE IS >= 10
|
||||
'do that
|
||||
CASE ELSE
|
||||
'default case
|
||||
END SELECT
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
10 INPUT "Enter 1,2 or 3: ";v
|
||||
20 GOTO v * 100
|
||||
99 STOP
|
||||
100 PRINT "Apple"
|
||||
110 STOP
|
||||
200 PRINT "Banana"
|
||||
210 STOP
|
||||
300 PRINT "Cherry"
|
||||
310 STOP
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
10 REM while loop
|
||||
20 L=0
|
||||
30 WHILE L<5
|
||||
40 PRINT L
|
||||
50 L=L+1
|
||||
60 WEND
|
||||
70 REM repeat loop
|
||||
80 L=1
|
||||
90 REPEAT
|
||||
100 PRINT L
|
||||
110 L=L+1
|
||||
120 UNTIL L>5
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
REM Single-line IF ... THEN ... ELSE (ELSE clause is optional):
|
||||
IF condition% THEN statements ELSE statements
|
||||
|
||||
REM Multi-line IF ... ENDIF (ELSE clause is optional):
|
||||
IF condition% THEN
|
||||
statements
|
||||
ELSE
|
||||
statements
|
||||
ENDIF
|
||||
|
||||
REM CASE ... ENDCASE (OTHERWISE clause is optional):
|
||||
CASE expression OF
|
||||
WHEN value1: statements
|
||||
WHEN value2: statements
|
||||
...
|
||||
OTHERWISE: statements
|
||||
ENDCASE
|
||||
|
||||
REM ON ... GOTO (ELSE clause is optional):
|
||||
ON expression% GOTO dest1, dest2 ... ELSE statements
|
||||
|
||||
REM ON ...GOSUB (ELSE clause is optional):
|
||||
ON expression% GOSUB dest1, dest2 ... ELSE statements
|
||||
|
||||
REM ON ... PROC (ELSE clause is optional):
|
||||
ON expression% PROCone, PROCtwo ... ELSE statements
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
v > "X",@ non-zero
|
||||
> & |
|
||||
> "0",@ zero
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
& #v_ "0",@ zero
|
||||
> "X",@ non-zero
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
if (i == 0)
|
||||
return "zero";
|
||||
elif (i % 2)
|
||||
return "odd";
|
||||
else
|
||||
return "even";
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
2+2:5
|
||||
& put$"Strange, must check that Bracmat interpreter."
|
||||
& 0
|
||||
| put$"That's what I thought."
|
||||
& Right
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
2+2
|
||||
: ( (<3|>5)
|
||||
& put$"Not quite, must check that Bracmat interpreter."
|
||||
| (3|5)
|
||||
& put$"Not far off, but must check that Bracmat interpreter some day."
|
||||
| ?
|
||||
& put$"That's what I thought."
|
||||
)
|
||||
|
|
@ -0,0 +1 @@
|
|||
[.]
|
||||
|
|
@ -0,0 +1 @@
|
|||
+[.]
|
||||
|
|
@ -0,0 +1 @@
|
|||
+[.-]
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
blsq ) 9 2.%{"Odd""Even"}ch
|
||||
"Odd"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
blsq ) 9^^2.%{+.}if
|
||||
10
|
||||
blsq ) 10^^2.%{+.}if
|
||||
10
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
blsq ) 10^^2.%{-.}\/{+.}\/ie
|
||||
11
|
||||
blsq ) 9^^2.%{-.}\/{+.}\/ie
|
||||
8
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
blsq ) {"Hate tomatos" "Like Bananas" "Hate Apples"}{"Tomato" "Banana" "Apple"}"Banana"Fi!!
|
||||
"Like Bananas"
|
||||
blsq ) {"Hate tomatos" "Like Bananas" "Hate Apples"}{"Tomato" "Banana" "Apple"}"Apple"Fi!!
|
||||
"Hate Apples"
|
||||
17
Task/Conditional-structures/C++/conditional-structures.cpp
Normal file
17
Task/Conditional-structures/C++/conditional-structures.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
template<bool Condition, typename ThenType, typename Elsetype> struct ifthenelse;
|
||||
|
||||
template<typename ThenType, typename ElseType> struct ifthenelse<true, ThenType, ElseType>
|
||||
{
|
||||
typedef ThenType type;
|
||||
};
|
||||
|
||||
template<typename ThenType, typename ElseType> struct ifthenelse<false, ThenType, ElseType>
|
||||
{
|
||||
typedef ElseType type;
|
||||
};
|
||||
|
||||
// example usage: select type based on size
|
||||
ifthenelse<INT_MAX == 32767, // 16 bit int?
|
||||
long int, // in that case, we'll need a long int
|
||||
int> // otherwise an int will do
|
||||
::type myvar; // define variable myvar with that type
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
set(num 5)
|
||||
|
||||
if(num GREATER 100)
|
||||
message("${num} is very large!")
|
||||
elseif(num GREATER 10)
|
||||
message("${num} is large.")
|
||||
else()
|
||||
message("${num} is small.")
|
||||
message("We might want a bigger number.")
|
||||
endif()
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
if condition-1
|
||||
imperative-statement-1
|
||||
else
|
||||
imperative-statement-2
|
||||
end-if
|
||||
|
||||
if condition-1
|
||||
if condition-a
|
||||
imperative-statement-1a
|
||||
else
|
||||
imperative-statement-1
|
||||
end-if
|
||||
else
|
||||
if condition-a
|
||||
imperative-statement-2a
|
||||
else
|
||||
imperative-statement-2
|
||||
end-if
|
||||
end-if
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
evaluate identifier-1
|
||||
when 'good'
|
||||
good-imperative-statement
|
||||
when 'bad'
|
||||
bad-imperative-statement
|
||||
when 'ugly'
|
||||
when 'awful'
|
||||
ugly-or-awful-imperative-statement
|
||||
when other
|
||||
default-imperative-statement
|
||||
end-evaluate
|
||||
|
||||
evaluate true
|
||||
when condition-1
|
||||
condition-1-imperative-statement
|
||||
when condition-2
|
||||
condition-2-imperative-statement
|
||||
when condition-3
|
||||
condition-3-imperative-statement
|
||||
when other
|
||||
default-condition-imperative-statement
|
||||
end-evaluate
|
||||
|
||||
evaluate identifier-1 also identifier-2
|
||||
when 10 also 20
|
||||
one-is-10-and-two-is-20-imperative-statement
|
||||
when 11 also 30
|
||||
one-is-11-and-two-is-30-imperative-statement
|
||||
when 20 also any
|
||||
one-is-20-and-two-is-anything-imperative-statement
|
||||
when other
|
||||
default-imperative-statement
|
||||
end-evaluate
|
||||
|
|
@ -0,0 +1 @@
|
|||
bool2int b = if b 1 0
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
case 6 * 7 of
|
||||
42 -> "Correct"
|
||||
_ -> "Wrong" // default, matches anything
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
answer 42 = True
|
||||
answer _ = False
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
answer x
|
||||
| x == 42 = True
|
||||
| otherwise = False
|
||||
|
||||
case 6 * 7 of
|
||||
n | n < 0 -> "Not even close"
|
||||
42 -> "Correct"
|
||||
// no default, could result in a run-time error
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(if (= 1 1) :yes :no) ; returns :yes
|
||||
|
||||
(if (= 1 2) :yes :no) ; returns :no
|
||||
|
||||
(if (= 1 2) :yes) ; returns nil
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(when x
|
||||
(print "hello")
|
||||
(println " world")
|
||||
5) ; when x is logical true, prints "hello world" and returns 5; otherwise does nothing, returns nil
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(cond
|
||||
(= 1 2) :no) ; returns nil
|
||||
|
||||
(cond
|
||||
(= 1 2) :no
|
||||
(= 1 1) :yes) ; returns :yes
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(cond
|
||||
(= 1 2) :no
|
||||
:else :yes) ; returns :yes
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(condp < 3
|
||||
4 :a ; cond equivalent would be (< 4 3) :a
|
||||
3 :b
|
||||
2 :c
|
||||
1 :d) ; returns :c
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(condp < 3
|
||||
4 :a
|
||||
3 :b
|
||||
:no-match) ; returns :no-match
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(case 2
|
||||
0 (println "0")
|
||||
1 (println "1")
|
||||
2 (println "2")) ; prints 2.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
if n == 1
|
||||
console.log "one"
|
||||
else if n == 2
|
||||
console.log "two"
|
||||
else
|
||||
console.log "other"
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
n = 1
|
||||
|
||||
switch n
|
||||
when 1
|
||||
console.log "one"
|
||||
when 2, 3
|
||||
console.log "two or three"
|
||||
else
|
||||
console.log "other"
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
s = if condition then "yup" else "nope"
|
||||
|
||||
# alternate form
|
||||
s = \
|
||||
if condition
|
||||
then "yup"
|
||||
else "nope"
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<cfif x eq 3>
|
||||
do something
|
||||
<cfelseif x eq 4>
|
||||
do something else
|
||||
<cfelse>
|
||||
do something else
|
||||
</cfif>
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<cfswitch expression="#x#">
|
||||
<cfcase value="1">
|
||||
do something
|
||||
</cfcase>
|
||||
<cfcase value="2">
|
||||
do something
|
||||
</cfcase>
|
||||
<cfdefaultcase>
|
||||
do something
|
||||
</cfdefaultcase>
|
||||
</cfswitch>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(if (= val 42)
|
||||
"That is the answer to life, the universe and everything"
|
||||
"Try again") ; the else clause here is optional
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(cond ((= val 1) (print "no"))
|
||||
((and (> val 3) (< val 6)) (print "yes"))
|
||||
((> val 99) (print "too far"))
|
||||
(T (print "no way, man!")))
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
if (condition)
|
||||
{
|
||||
// Some Task
|
||||
}
|
||||
|
||||
if (condition)
|
||||
{
|
||||
// Some Task
|
||||
}
|
||||
else if (condition2)
|
||||
{
|
||||
// Some Task
|
||||
}
|
||||
else
|
||||
{
|
||||
// Some Task
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
// if condition is true var will be set to 1, else false.
|
||||
int var = condition ? 1 : 2;
|
||||
1
Task/Conditional-structures/D/conditional-structures-1.d
Normal file
1
Task/Conditional-structures/D/conditional-structures-1.d
Normal file
|
|
@ -0,0 +1 @@
|
|||
const i = 5; static if (i == 7) { ... } else { ... }
|
||||
9
Task/Conditional-structures/D/conditional-structures-2.d
Normal file
9
Task/Conditional-structures/D/conditional-structures-2.d
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
auto i = 5;
|
||||
// is(T: U) tests if T is implicitly castable to U.
|
||||
// typeof(var) is the type of the variable.
|
||||
// also: is(T==U) checks if T is U.
|
||||
static if (is(typeof(i) : int)) {
|
||||
...
|
||||
} else {
|
||||
...
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
a = 3
|
||||
if( a == 1 ){
|
||||
io.writeln( 'a == 1' )
|
||||
}elif( a== 3 ){
|
||||
io.writeln( 'a == 3' )
|
||||
}else{
|
||||
io.writeln( 'a is neither 1 nor 3' )
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
a = 3
|
||||
switch( a ){
|
||||
case 0: io.writeln( 'case 0' )
|
||||
case 1, 2: io.writeln( 'case 1,2' )
|
||||
case 3 ... 5: io.writeln( 'case 3...5' )
|
||||
default: io.writeln( 'default' )
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
if a:
|
||||
pass
|
||||
elseif b:
|
||||
pass
|
||||
else: # c, maybe?
|
||||
pass
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
if (input.Field == "Hello World") {
|
||||
sVar = "good";
|
||||
} else if (input.Field == "Bye World") {
|
||||
sVar = "bad";
|
||||
} else {
|
||||
sVar = "neutral";
|
||||
}
|
||||
7
Task/Conditional-structures/E/conditional-structures-1.e
Normal file
7
Task/Conditional-structures/E/conditional-structures-1.e
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
if (okay) {
|
||||
println("okay")
|
||||
} else if (!okay) {
|
||||
println("not okay")
|
||||
} else {
|
||||
println("not my day")
|
||||
}
|
||||
1
Task/Conditional-structures/E/conditional-structures-2.e
Normal file
1
Task/Conditional-structures/E/conditional-structures-2.e
Normal file
|
|
@ -0,0 +1 @@
|
|||
println(okay.pick("okay", "not okay"))
|
||||
5
Task/Conditional-structures/E/conditional-structures-3.e
Normal file
5
Task/Conditional-structures/E/conditional-structures-3.e
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
okay.pick(fn {
|
||||
println("okay")
|
||||
}, fn {
|
||||
println("not okay")
|
||||
})()
|
||||
7
Task/Conditional-structures/E/conditional-structures-4.e
Normal file
7
Task/Conditional-structures/E/conditional-structures-4.e
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def expression := ["+", [1, 2]]
|
||||
|
||||
def value := switch (expression) {
|
||||
match [`+`, [a, b]] { a + b }
|
||||
match [`*`, [a, b]] { a * b }
|
||||
match [op, _] { throw(`unknown operator: $op`) }
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
show_if_with_parenthesis = fn (Num) {
|
||||
if (Num == 1) {
|
||||
io.format("is one~n")
|
||||
}
|
||||
else if (Num === 2) {
|
||||
io.format("is two~n")
|
||||
}
|
||||
else {
|
||||
io.format("not one not two~n")
|
||||
}
|
||||
}
|
||||
|
||||
show_if_without_parenthesis = fn (Num) {
|
||||
if Num == 1 {
|
||||
io.format("is one~n")
|
||||
}
|
||||
else if Num === 2 {
|
||||
io.format("is two~n")
|
||||
}
|
||||
else {
|
||||
io.format("not one not two~n")
|
||||
}
|
||||
}
|
||||
|
||||
show_switch_with_parenthesis = fn (Num) {
|
||||
switch (Num) {
|
||||
case (1) {
|
||||
io.format("one!~n")
|
||||
}
|
||||
case (2) {
|
||||
io.format("two!~n")
|
||||
}
|
||||
else {
|
||||
io.format("else~n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
show_switch_without_parenthesis = fn (Num) {
|
||||
switch (Num) {
|
||||
case 1 {
|
||||
io.format("one!~n")
|
||||
}
|
||||
case 2 {
|
||||
io.format("two!~n")
|
||||
}
|
||||
else {
|
||||
io.format("else~n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@public
|
||||
run = fn () {
|
||||
show_if_with_parenthesis(random.uniform(3))
|
||||
show_if_without_parenthesis(random.uniform(3))
|
||||
|
||||
show_switch_with_parenthesis(random.uniform(3))
|
||||
show_switch_without_parenthesis(random.uniform(3))
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
if x < 0 then 0 else x
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
getX x | x < 0 = 0
|
||||
| else = x
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
force (x::xs) = x :: force xs
|
||||
force [] = []
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
force lst = match lst with
|
||||
x::xs = x :: force xs
|
||||
[] = []
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
case X of
|
||||
{N,M} when N > M -> M;
|
||||
{N,M} when N < M -> N;
|
||||
_ -> equal
|
||||
end.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{N,M} = X,
|
||||
if
|
||||
N > M -> M;
|
||||
N < M -> N;
|
||||
true -> equal
|
||||
end.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
test({N,M}) when N > M -> M;
|
||||
test({N,M}) when N < M -> N;
|
||||
test(_) -> equal.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
( condition ) IF ( true statements ) THEN
|
||||
( condition ) IF ( true statements ) ELSE ( false statements ) THEN
|
||||
|
|
@ -0,0 +1 @@
|
|||
10 < IF ." Less than 10" ELSE ." Greater than or equal to 10" THEN
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
( n -- ) CASE
|
||||
( integer ) OF ( statements ) ENDOF
|
||||
( integer ) OF ( statements ) ENDOF
|
||||
( default instructions )
|
||||
ENDCASE
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
: test-case ( n -- )
|
||||
CASE
|
||||
0 OF ." Zero!" ENDOF
|
||||
1 OF ." One!" ENDOF
|
||||
." Some other number!"
|
||||
ENDCASE ;
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
: switch
|
||||
CREATE ( default-xt [count-xts] count -- ) DUP , 0 DO , LOOP ,
|
||||
DOES> ( u -- ) TUCK @ MIN 1+ CELLS + @ EXECUTE ;
|
||||
|
||||
:NONAME ." Out of range!" ;
|
||||
:NONAME ." nine" ;
|
||||
:NONAME ." eight" ;
|
||||
:NONAME ." seven" ;
|
||||
:NONAME ." six" ;
|
||||
:NONAME ." five" ;
|
||||
:NONAME ." four" ;
|
||||
:NONAME ." three" ;
|
||||
:NONAME ." two" ;
|
||||
:NONAME ." one" ;
|
||||
:NONAME ." zero" ;
|
||||
10 switch digit
|
||||
|
||||
8 digit \ eight
|
||||
34 digit \ Out of range!
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
if ( a .gt. 20.0 ) then
|
||||
q = q + a**2
|
||||
else if ( a .ge. 0.0 ) then
|
||||
q = q + 2*a**3
|
||||
else
|
||||
q = q - a
|
||||
end if
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
select case (i)
|
||||
case (21:) ! matches all integers greater than 20
|
||||
q = q + i**2
|
||||
case (0:20) ! matches all integers between 0 and 20 (inclusive)
|
||||
q = q + 2*i**3
|
||||
case default ! matches all other integers (negative in this particular case)
|
||||
q = q - I
|
||||
end select
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
! diffusion grid time step
|
||||
where (edge_type(1:n,1:m) == center)
|
||||
anew(1:n,1:m) = (a(1:n,1:m) + a(0:n-1,1:m) + a(2:n+1,1:m) + a(1:n,0:m-1) + a(1:n,2:m+1)) / 5
|
||||
|
||||
elsewhere (edge_type(1:n,1:m) == left)
|
||||
anew(1:n,1:m) = (a(1:n,1:m) + 2*a(2:n+1,1:m) + a(1:n,0:m-1) + a(1:n,2:m+1)) / 5
|
||||
|
||||
elsewhere (edge_type(1:n,1:m) == right)
|
||||
anew(1:n,1:m) = (a(1:n,1:m) + 2*a(0:n-1,1:m) + a(1:n,0:m-1) + a(1:n,2:m+1)) / 5
|
||||
|
||||
elsewhere (edge_type(1:n,1:m) == top)
|
||||
anew(1:n,1:m) = (a(1:n,1:m) + a(0:n-1,1:m) + a(2:n+1,1:m) + 2*a(1:n,2:m+1)) / 5
|
||||
|
||||
elsewhere (edge_type(1:n,1:m) == bottom)
|
||||
anew(1:n,1:m) = (a(1:n,1:m) + a(0:n-1,1:m) + a(2:n+1,1:m) + 2*a(1:n,0:m-1)) / 5
|
||||
|
||||
elsewhere (edge_type(1:n,1:m) == left_top)
|
||||
anew(1:n,1:m) = (a(1:n,1:m) + 2*a(2:n+1,1:m) + 2*a(1:n,2:m+1)) / 5
|
||||
|
||||
elsewhere (edge_type(1:n,1:m) == right_top)
|
||||
anew(1:n,1:m) = (a(1:n,1:m) + 2*a(0:n-1,1:m) + 2*a(1:n,2:m+1)) / 5
|
||||
|
||||
elsewhere (edge_type(1:n,1:m) == left_bottom)
|
||||
anew(1:n,1:m) = (a(1:n,1:m) + 2*a(2:n+1,1:m) + 2*a(1:n,0:m-1)) / 5
|
||||
|
||||
elsewhere (edge_type(1:n,1:m) == right_bottom)
|
||||
anew(1:n,1:m) = (a(1:n,1:m) + 2*a(0:n-1,1:m) + 2*a(1:n,0:m-1)) / 5
|
||||
|
||||
elsewhere ! sink/source, does not change
|
||||
anew(1:n,1:m) = a(1:n,1:m)
|
||||
end where
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
if booleanExpression {
|
||||
statements
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
treadmill: for {
|
||||
switch {
|
||||
case true:
|
||||
break treadmill
|
||||
}
|
||||
}
|
||||
fmt.Println("I'm off!")
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
if booleanExpression {
|
||||
statements
|
||||
} else {
|
||||
other
|
||||
statements
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue