langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
|
|
@ -0,0 +1,3 @@
|
|||
if (the_answer == 42) FindQuestion() else Foo();
|
||||
when (stock.price < buy_order) stock.Buy();
|
||||
unless (text < "") Write(text);
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
match(x)
|
||||
{
|
||||
|1 => "x is one"
|
||||
|x when (x < 5) => "x is less than five"
|
||||
|_ => "x is at least five"
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
-- simple construct
|
||||
if logicalCondition then conditionWasTrue()
|
||||
else conditionWasFalse()
|
||||
|
||||
-- multi-line is ok too
|
||||
if logicalCondition
|
||||
then
|
||||
conditionWasTrue()
|
||||
else
|
||||
conditionWasFalse()
|
||||
|
||||
-- using block stuctures
|
||||
if logicalCondition then do
|
||||
conditionWasTrue()
|
||||
...
|
||||
end
|
||||
else do
|
||||
conditionWasFalse()
|
||||
...
|
||||
end
|
||||
|
||||
-- if/else if...
|
||||
if logicalCondition1 then do
|
||||
condition1WasTrue()
|
||||
...
|
||||
end
|
||||
else if logicalCondition2 then do
|
||||
condition2WasTrue()
|
||||
...
|
||||
end
|
||||
else do
|
||||
conditionsWereFalse()
|
||||
...
|
||||
end
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
-- simple construct
|
||||
select
|
||||
when logicalCondition1 then condition1()
|
||||
when logicalCondition2 then condition2()
|
||||
otherwise conditionDefault()
|
||||
end
|
||||
|
||||
-- set up a catch block to intercept missing OTHERWISE clause
|
||||
do
|
||||
select
|
||||
when logicalCondition1 then condition1()
|
||||
when logicalCondition2 then condition2()
|
||||
end
|
||||
catch ex1 = NoOtherwiseException
|
||||
ex1.printStackTrace()
|
||||
end
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
-- simple construct
|
||||
select case cc
|
||||
when 'A' then say 'the case is A'
|
||||
when 'B' then say 'the case is B'
|
||||
otherwise say 'selection not recognized'
|
||||
end
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
select
|
||||
when cc == 'A' then ...
|
||||
when cc == 'B' then ...
|
||||
...
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
select label sl protect cc case cc
|
||||
when 'A' then do
|
||||
say 'the case is A'
|
||||
if logicalCondition then leave sl -- just to use the lable
|
||||
say '...'
|
||||
end
|
||||
when 'B' then do
|
||||
say 'the case is B'
|
||||
say '...'
|
||||
end
|
||||
otherwise
|
||||
say 'selection not recognized'
|
||||
say '...'
|
||||
catch exs = RuntimeException
|
||||
say 'Gronk!'
|
||||
exs.printStackTrace()
|
||||
finally
|
||||
say 'selection done'
|
||||
say 'TTFN'
|
||||
end sl
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
let condition = true
|
||||
|
||||
if condition then
|
||||
1 (* evaluate something *)
|
||||
else
|
||||
2 (* evaluate something *)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
if condition then begin
|
||||
(); (* evaluate things for side effects *)
|
||||
5
|
||||
end
|
||||
else begin
|
||||
(); (* evaluate things for side effects *)
|
||||
42
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
match expression with
|
||||
| 0 -> () (* evaluate something *)
|
||||
| 1 -> () (* evaluate something *)
|
||||
| n when n mod 2 = 0 -> () (* evaluate something *)
|
||||
| _ -> () (* evaluate something *)
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
a := GetValue();
|
||||
if(a < 5) {
|
||||
"less than 5"->PrintLine();
|
||||
}
|
||||
else if(a > 5) {
|
||||
"greater than 5"->PrintLine();
|
||||
}
|
||||
else {
|
||||
"equal to 5"->PrintLine();
|
||||
};
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
a := GetValue();
|
||||
select(a) {
|
||||
label 5: {
|
||||
"equal to 5"->PrintLine();
|
||||
}
|
||||
|
||||
label 7: {
|
||||
"equal to 7"->PrintLine();
|
||||
}
|
||||
|
||||
other: {
|
||||
"another value"->PrintLine();
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
if (condition)
|
||||
% body
|
||||
endif
|
||||
|
||||
if (condition)
|
||||
% body
|
||||
else
|
||||
% otherwise body
|
||||
endif
|
||||
|
||||
if (condition1)
|
||||
% body
|
||||
elseif (condition2)
|
||||
% body 2
|
||||
else
|
||||
% otherwise body
|
||||
endif
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
switch( expression )
|
||||
case label1
|
||||
% code for label1
|
||||
case label2
|
||||
% code for label2
|
||||
otherwise
|
||||
% none of the previous
|
||||
endswitch
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
switch ( x )
|
||||
case 1
|
||||
disp("it is 1");
|
||||
case { 5,6,7 }
|
||||
disp("it is 5, or 6 or 7");
|
||||
otherwise
|
||||
disp("unknown!");
|
||||
endswitch
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
if a then b=c else b=d
|
||||
|
||||
if a=0
|
||||
b=c
|
||||
elseif a<0
|
||||
b=d
|
||||
else
|
||||
b=e
|
||||
end if
|
||||
|
||||
select case a
|
||||
case 'A'
|
||||
v=21
|
||||
case 'B'
|
||||
v=22
|
||||
case 1 to 64
|
||||
v=a+300
|
||||
case else
|
||||
v=0
|
||||
end select
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
proc {PrintParity X}
|
||||
if {IsEven X} then
|
||||
{Show even}
|
||||
elseif {IsOdd X} then
|
||||
{Show odd}
|
||||
else
|
||||
{Show 'should not happen'}
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fun {Max X Y}
|
||||
if X > Y then X else Y end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
fun {Fac X}
|
||||
case X of 0 then 1
|
||||
[] _ then X * {Fac X-1}
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
if(condition, do_if_true, do_if_false)
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
if condition then
|
||||
statement;
|
||||
else
|
||||
statement;
|
||||
|
||||
if condition then
|
||||
do;
|
||||
statement-1;
|
||||
.
|
||||
.
|
||||
statement-n;
|
||||
end;
|
||||
else
|
||||
statement;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
select (i); /* select on value of variable */
|
||||
when (1,4,9)
|
||||
do;
|
||||
statement(s)
|
||||
end;
|
||||
|
||||
when (11, 42)
|
||||
do;
|
||||
statement(s)
|
||||
end;
|
||||
|
||||
other /* everything else */
|
||||
do;
|
||||
statement(s)
|
||||
end;
|
||||
end;
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
select; /* select first matching condition */
|
||||
when (i = 4);
|
||||
do;
|
||||
statement(s)
|
||||
end;
|
||||
|
||||
when (this = that)
|
||||
do;
|
||||
statement(s)
|
||||
end;
|
||||
|
||||
when (string = 'ABCDE')
|
||||
do;
|
||||
statement(s)
|
||||
end;
|
||||
|
||||
other
|
||||
do;
|
||||
statement(s)
|
||||
end;
|
||||
end;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
IF condition1 THEN
|
||||
procedure1
|
||||
ELSE
|
||||
procedure3;
|
||||
|
||||
IF condition1 THEN
|
||||
BEGIN
|
||||
procedure1;
|
||||
procedure2;
|
||||
END
|
||||
ELSE
|
||||
procedure3;
|
||||
|
||||
IF condition 1 THEN
|
||||
BEGIN
|
||||
procedure1;
|
||||
procedure2;
|
||||
END
|
||||
ELSE
|
||||
BEGIN
|
||||
procedure3;
|
||||
procedure4;
|
||||
END;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
case i of
|
||||
1,4,9: { executed if i is 1, 4 or 9 }
|
||||
DoSomething;
|
||||
11, 13 .. 17: { executed if i is 11, 13, 14, 15, 16 or 17 }
|
||||
DoSomethingElse;
|
||||
42: { executed only if i is 42 }
|
||||
DoSomeOtherThing;
|
||||
else
|
||||
DoYetAnotherThing;
|
||||
end;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
Case X of
|
||||
'A' : statement ;
|
||||
'B' : statement ;
|
||||
in ['C'..'W'] : statement ;
|
||||
else
|
||||
Statement ;
|
||||
end;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
if won() -> $prize {
|
||||
say "You won $prize.";
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
given lc prompt("Done? ") {
|
||||
when 'yes' { return }
|
||||
when 'no' { next }
|
||||
default { say "Please answer either yes or not." }
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
$expression ?? do_something !! do_fallback
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
if condition then
|
||||
;;; Action
|
||||
endif;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#_IF condition1
|
||||
/* Variant 1 */
|
||||
#_ELSEIF condition2
|
||||
/* Variant 2 */
|
||||
#_ELSE
|
||||
/* Variant 3 */
|
||||
#_ENDIF
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
if condition then
|
||||
;;; Action1
|
||||
else
|
||||
;;; Alternative action
|
||||
endif;
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
if condition1 then
|
||||
;;; Action1
|
||||
elseif condition2 then
|
||||
;;; Action1
|
||||
elseif condition2 then
|
||||
;;; Action2
|
||||
elseif condition3 then
|
||||
;;; Action3
|
||||
else
|
||||
;;; Alternative action
|
||||
endif;
|
||||
|
|
@ -0,0 +1 @@
|
|||
unless condition then /* Action */ endunless;
|
||||
|
|
@ -0,0 +1 @@
|
|||
if not(condition) then /* Action */ endif;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
if condition1 then
|
||||
;;; Action1
|
||||
elseunless condition2 then
|
||||
;;; Action2
|
||||
endif;
|
||||
;;; Action2
|
||||
endif;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
if condition1 then
|
||||
;;; Action1
|
||||
elseif not(condition2) then
|
||||
;;; Action2
|
||||
endif;
|
||||
|
|
@ -0,0 +1 @@
|
|||
if x > 0 then 1 elseif x < 0 then -1 else 0 endif -> sign_x ;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
switchon(x)
|
||||
case .isstring then printf('A1');
|
||||
notcase .isinteger then printf('A2');
|
||||
case = 2 orcase = 3 then printf('A3');
|
||||
case > 4 andcase < 15 then printf('A4');
|
||||
else printf('A5');
|
||||
endswitchon;
|
||||
|
|
@ -0,0 +1 @@
|
|||
9 10 lt {(9 is less than 10) show} if
|
||||
|
|
@ -0,0 +1 @@
|
|||
/a 5 lt {(yeah)} {(nope)} ifelse show
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# standard if
|
||||
if (condition) {
|
||||
# ...
|
||||
}
|
||||
|
||||
# if-then-else
|
||||
if (condition) {
|
||||
# ...
|
||||
} else {
|
||||
# ...
|
||||
}
|
||||
|
||||
# if-then-elseif-else
|
||||
if (condition) {
|
||||
# ...
|
||||
} elseif (condition2) {
|
||||
# ...
|
||||
} else {
|
||||
# ...
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
# standard switch
|
||||
switch ($var) {
|
||||
1 { "Value was 1" }
|
||||
2 { "Value was 2" }
|
||||
default { "Value was something else" }
|
||||
}
|
||||
|
||||
# switch with wildcard matching
|
||||
switch -Wildcard ($var) {
|
||||
"a*" { "Started with a" }
|
||||
"*x" { "Ended with x" }
|
||||
}
|
||||
|
||||
# switch with regular expression matching
|
||||
switch -Regex ($var) {
|
||||
"[aeiou]" { "Contained a consonant" }
|
||||
"(.)\1" { "Contained a character twice in a row" }
|
||||
}
|
||||
|
||||
# switch allows for scriptblocks too
|
||||
switch ($var) {
|
||||
{ $_ % 2 -eq 0 } { "Number was even" }
|
||||
{ $_ -gt 100 } { "Number was greater than 100" }
|
||||
}
|
||||
|
||||
# switch allows for handling a file
|
||||
switch -Regex -File somefile.txt {
|
||||
"\d+" { "Line started with a number" }
|
||||
"\s+" { "Line started with whitespace" }
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
If a = 0
|
||||
Debug "a = 0"
|
||||
|
||||
ElseIf a > 0
|
||||
Debug "a > 0"
|
||||
|
||||
Else
|
||||
Debug "a < 0"
|
||||
|
||||
EndIf
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
Variable = 2
|
||||
|
||||
Select Variable
|
||||
Case 0
|
||||
Debug "Variable = 0"
|
||||
|
||||
Case 10, 11, 99
|
||||
Debug "Variable is 10, 11 or 99"
|
||||
|
||||
Case 20 To 30
|
||||
Debug "Variable >= 20 And Variable <= 30"
|
||||
|
||||
Default
|
||||
Debug "Variable = something else..."
|
||||
EndSelect
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
CompilerIf #PB_Compiler_OS = #PB_OS_Linux And #PB_Compiler_Processor = #PB_Processor_x86
|
||||
Debug "Compiled on x86 Linux"
|
||||
CompilerElse
|
||||
Debug "Compiled on something else"
|
||||
CompilerEndIf
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
CompilerSelect #PB_Compiler_OS
|
||||
CompilerCase #PB_OS_Linux
|
||||
Debug "Compiled on Linux"
|
||||
CompilerCase #PB_OS_Windows
|
||||
Debug "Compiled on Windows"
|
||||
CompilerCase #PB_OS_MacOS
|
||||
Debug "Compiled on Mac OS"
|
||||
CompilerDefault
|
||||
Debug "Compiled on something else"
|
||||
CompilerEndIf
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
if (x==1)
|
||||
{
|
||||
// do something
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
if (x==1)
|
||||
{
|
||||
// do something if x is 1
|
||||
y = const.pi;
|
||||
else
|
||||
// do something if x is not 1
|
||||
y = sin(const.pi*(1-x)) / (1-x);
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
if (x==1)
|
||||
{
|
||||
// do something if x is 1
|
||||
y = const.pi;
|
||||
else if (x == 2)
|
||||
{
|
||||
// do something if x is 2
|
||||
y = sin(const.pi*(1-x)) / (1-x);
|
||||
else
|
||||
// do something in all the other cases
|
||||
y = rand();
|
||||
}}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
( condition ) [ ( true statements ) ] ifTrue
|
||||
( condition ) [ ( false statements ) ] ifFalse
|
||||
( condition ) [ ( true statements ) ] [ ( false statements ) ] if
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
: foo ( n- )
|
||||
[ 1 = ] [ drop ( if quote evaluates to true ) ] when
|
||||
[ 2 = ] [ drop ( if quote evaluates to true ) ] when
|
||||
[ 3 = ] [ drop ( if quote evaluates to true ) ] when
|
||||
drop ( default action ) ;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
If[cond]
|
||||
|:
|
||||
Do Something[]
|
||||
:||:
|
||||
Do Something Else[]
|
||||
:|
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
' Boolean Evaluations
|
||||
'
|
||||
' > Greater Than
|
||||
' < Less Than
|
||||
' >= Greater Than Or Equal To
|
||||
' <= Less Than Or Equal To
|
||||
' = Equal to
|
||||
|
||||
x = 0
|
||||
|
||||
if x = 0 then print "Zero"
|
||||
|
||||
' --------------------------
|
||||
' if/then/else
|
||||
if x = 0 then
|
||||
print "Zero"
|
||||
else
|
||||
print "Nonzero"
|
||||
end if
|
||||
|
||||
' --------------------------
|
||||
' not
|
||||
if x then
|
||||
print "x has a value."
|
||||
end if
|
||||
if not(x) then
|
||||
print "x has no value."
|
||||
end if
|
||||
|
||||
' --------------------------
|
||||
' if .. end if
|
||||
if x = 0 then
|
||||
print "Zero"
|
||||
goto [surprise]
|
||||
end if
|
||||
wait
|
||||
|
||||
if x = 0 then goto [surprise]
|
||||
print "No surprise."
|
||||
wait
|
||||
|
||||
[surprise]
|
||||
print "Surprise!"
|
||||
wait
|
||||
|
||||
' --------------------------
|
||||
' case numeric
|
||||
num = 3
|
||||
|
||||
select case num
|
||||
case 1
|
||||
print "one"
|
||||
|
||||
case 2
|
||||
print "two"
|
||||
|
||||
case 3
|
||||
print "three"
|
||||
|
||||
case else
|
||||
print "other number"
|
||||
|
||||
end select
|
||||
|
||||
' --------------------------
|
||||
' case character
|
||||
var$="blue"
|
||||
|
||||
select case var$
|
||||
|
||||
case "red"
|
||||
print "red"
|
||||
|
||||
case "green"
|
||||
print "green"
|
||||
|
||||
case else
|
||||
print "color unknown"
|
||||
|
||||
end select
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
if x == 1
|
||||
foo()
|
||||
else if x == 2
|
||||
bar()
|
||||
else
|
||||
foobar()
|
||||
end if
|
||||
|
|
@ -0,0 +1 @@
|
|||
.if(x == 1, "hello", "world")
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
A = "true"
|
||||
* "if-then-else"
|
||||
if A "true" :s(goTrue)f(goFalse)
|
||||
goTrue output = "A is TRUE" :(fi)
|
||||
goFalse output = "A is not TRUE" :(fi)
|
||||
fi
|
||||
|
||||
* "switch"
|
||||
switch A ("true" | "false") . switch :s($("case" switch))f(default)
|
||||
casetrue output = "A is TRUE" :(esac)
|
||||
casefalse output = "A is FALSE" :(esac)
|
||||
default output = "A is neither FALSE nor TRUE"
|
||||
esac
|
||||
end
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
case when a then b else c end
|
||||
|
||||
declare @n int
|
||||
set @n=124
|
||||
print case when @n=123 then 'equal' else 'not equal' end
|
||||
|
||||
--If/ElseIf expression
|
||||
set @n=5
|
||||
print case when @n=3 then 'Three' when @n=4 then 'Four' else 'Other' end
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
declare @n int
|
||||
set @n=123
|
||||
if @n=123
|
||||
BEGIN --begin/end needed if more than one statement inside
|
||||
print 'one two three'
|
||||
END
|
||||
ELSE
|
||||
if @n=124 print 'one two four'
|
||||
else print 'other'
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
if condition then
|
||||
statement
|
||||
end if;
|
||||
|
||||
if condition then
|
||||
statement1
|
||||
else
|
||||
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;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
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;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
"Conditionals in Slate are really messages sent to Boolean objects. Like Smalltalk. (But the compiler might optimize some cases)"
|
||||
balance > 0
|
||||
ifTrue: [inform: 'still sitting pretty!'.]
|
||||
ifFalse: [inform: 'No money till payday!'.].
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
c@(Net URLPathEncoder traits) convert
|
||||
[ | byte1 byte2 byte3 digit1 digit2|
|
||||
[c in isAtEnd] whileFalse:
|
||||
[byte1: c in next.
|
||||
byte1 caseOf: {
|
||||
$+ -> [c out nextPut: $\s].
|
||||
$% -> [byte2: c in next.
|
||||
byte3: c in next.
|
||||
digit1: (byte2 toDigit: 16).
|
||||
digit2: (byte3 toDigit: 16).
|
||||
digit1 isNil \/ [digit2 isNil] ifTrue: [error: 'Error reading hex sequence after %'].
|
||||
c out nextPut: (digit1 * 16 + digit2 as: c out elementType)].
|
||||
} otherwise: [c out nextPut: byte1].
|
||||
].
|
||||
].
|
||||
|
|
@ -0,0 +1 @@
|
|||
[p isAtEnd] whileFalse: [p next evaluate]].
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
$$ MODE TUSCRIPT
|
||||
|
||||
condition="c"
|
||||
IF (condition=="a") THEN
|
||||
---> do something
|
||||
ELSEIF (condition=="b") THEN
|
||||
---> do something
|
||||
ELSE
|
||||
---> do something
|
||||
ENDIF
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
$$ MODE TUSCRIPT
|
||||
|
||||
days="Monday'Tuesday'Wednesday'Thursday'Friday'Saturday'Sunday"
|
||||
dayofweek=DATE (today,day,month,year,number)
|
||||
day=SELECT (days,#dayofweek)
|
||||
|
||||
SELECT day
|
||||
CASE "Monday"
|
||||
---> do something
|
||||
CASE "Saturday","Sunday"
|
||||
---> do something
|
||||
DEFAULT
|
||||
---> do something
|
||||
ENDSELECT
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
@(choose :shortest x)
|
||||
@x:@y
|
||||
@(or)
|
||||
@x<--@y
|
||||
@(or)
|
||||
@x+@y
|
||||
@(end)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
@(all)
|
||||
@x:y@
|
||||
@z<-@w
|
||||
@(and)
|
||||
@(output)
|
||||
We have a match: (x, y, z, w) = (@x, @y, @z, @w).
|
||||
@(end)
|
||||
@(end)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
@# match a line which contains some piece of text x
|
||||
@# after the rightmost occurence of : such that the same piece
|
||||
@# of text also occurs at the start of the line preceded by -->
|
||||
@(all)
|
||||
@*junk:@x
|
||||
@(and)
|
||||
-->@x@/.*/
|
||||
@(end)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
100 100 = [ ." True\n" ] ifTrue
|
||||
100 200 = [ ." True\n" ] ifTrue
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
100 100 = [ ." True\n" ] ifFalse
|
||||
100 200 = [ ." True\n" ] ifFalse
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
100 100 = [ ." Equal\n" ] [ ." Not Equal\n" ] ifTrueFalse
|
||||
100 200 = [ ." Equal\n" ] [ ." Not Equal\n" ] ifTrueFalse
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// numbers and objects
|
||||
if(%num == 1)
|
||||
{
|
||||
foo();
|
||||
}
|
||||
else if(%obj == MyObject.getID())
|
||||
{
|
||||
bar();
|
||||
}
|
||||
else
|
||||
{
|
||||
deusEx();
|
||||
}
|
||||
|
||||
// strings
|
||||
if(%str $= "Hello World")
|
||||
{
|
||||
foo();
|
||||
}
|
||||
else if(%str $= "Bye World")
|
||||
{
|
||||
bar();
|
||||
}
|
||||
else
|
||||
{
|
||||
deusEx();
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
// numbers and objects
|
||||
switch(%num)
|
||||
{
|
||||
case 1:
|
||||
one();
|
||||
case 2:
|
||||
twoThreeOrFour();
|
||||
case 3:
|
||||
twoThreeOrFour();
|
||||
case 4:
|
||||
twoThreeOrFour();
|
||||
case 5:
|
||||
five();
|
||||
case MyObject.getID():
|
||||
anObject();
|
||||
default:
|
||||
everythingElse();
|
||||
}
|
||||
|
||||
// strings
|
||||
switch$(%str)
|
||||
{
|
||||
case "Hello":
|
||||
arrival();
|
||||
case "Goodbye":
|
||||
departure();
|
||||
default:
|
||||
somethingElse();
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
%formatted = %str @ ((getSubStr(%str,strLen(%str) - 1,1) $= "s") ? "'" : "'s");
|
||||
|
|
@ -0,0 +1 @@
|
|||
true ["yes" print] ["no" print] branch
|
||||
|
|
@ -0,0 +1 @@
|
|||
true ["yes" print] when
|
||||
|
|
@ -0,0 +1 @@
|
|||
false ["no" print] unless
|
||||
|
|
@ -0,0 +1 @@
|
|||
if test 3 -lt 5; then echo '3 is less than 5'; fi
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
if test 4 -ge 6; then
|
||||
echo '4 is greater than or equal to 6'
|
||||
elif test 4 -lt 6; then
|
||||
echo '4 is less than 6'
|
||||
else
|
||||
echo '4 compares not to 6'
|
||||
fi
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
case value in
|
||||
choicea)
|
||||
foo
|
||||
;;
|
||||
choiceb)
|
||||
bar
|
||||
;;
|
||||
esac
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
test 3 -lt 5 && echo '3 is less than 5'
|
||||
test 4 -ge 6 || echo '4 is not greater than or equal to 6'
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# This is a while loop
|
||||
l=1
|
||||
while [ l -le 5 ]; do
|
||||
echo $l
|
||||
done
|
||||
|
||||
# This is an until loop
|
||||
l=1
|
||||
until [ l -eq 5 ]; do
|
||||
echo $l
|
||||
done
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
if (3 < 5) echo '3 is less than 5'
|
||||
if ({ grep -q ^root: /etc/passwd }) echo 'passwd has root'
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
if (4 >= 6) then
|
||||
echo '4 is greater than or equal to 6'
|
||||
else if (4 < 6) then
|
||||
echo '4 is less than 6'
|
||||
else
|
||||
echo '4 compares not to 6'
|
||||
endif
|
||||
6
Task/Conditional-structures/V/conditional-structures-1.v
Normal file
6
Task/Conditional-structures/V/conditional-structures-1.v
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[true]
|
||||
['is true' puts]
|
||||
['is false' puts]
|
||||
ifte
|
||||
|
||||
=is true
|
||||
4
Task/Conditional-structures/V/conditional-structures-2.v
Normal file
4
Task/Conditional-structures/V/conditional-structures-2.v
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[true]
|
||||
['is true' puts]
|
||||
if
|
||||
=is true
|
||||
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