-
Notifications
You must be signed in to change notification settings - Fork 4
Control flow
Determines if a given statement is true.
[COMPARE (num1: number) (check: operator) (num2: number)]
operator is a string of larger-than (>), smaller-than (<), larger-or-equal-to (>=), smaller-or-equal-to (<=), equal-to (= or ==), or not-equal-to (!=)
Example code:
[COMPARE 3 == 3]
> true
[COMPARE 5 == 3]
> false
Takes in 3 arguments. If the first argument is not falsy, the second argument is run. If not, the third argument is run.
A falsy value is either 0, an empty string/array, or false.
[IF (comparison: bool) (true: function) (false: optional function)]
[IF [COMPARE 7 == 3] [USERNAME] "no, 7 is not equivalent to 3"]
> "no, 7 is not equivalent to 3"
[IF [COMPARE 3 == 3] [USERNAME] "no, 3 is not equivalent to 3"]
> "Infernity"
Takes in code as an argument, and then repeats it 'X' times.
[LOOP (times: int) (code: function)]
Example code:
[LOOP 10 [CHOOSECHAR "abcdefgh12345"]]
> ['1', 'e', '4', 'd', 'c', 'g', 'g', 'e', 'h', 'f']
Tries to run code. If the code returns an error, it runs the second argument given.
[TRY (code: function) (on error: function or string)]
Example code:
> [TRY [DIV 0 0] "error: oh no 0/0 is an error"]
"error: oh no 0/0 is an error"
Returns out of a loop with a value, even if conditions are not met. Returns at end of a loop. Also works with WHILE.
[RETURN (return val: any)]
Example code:
> [DEFINE x 0] [WHILE [COMPARE [VAR x] < 3] [DEFINE x [ADD [VAR x] 1]]] [RETURN "a"]]
"a"
Runs the second argument repeatedly until the first argument is false.
[WHILE (keepGoing: bool) (func1: function) (func2: function...)]
> [DEFINE x 0] [WHILE [COMPARE [VAR x] < 3] [DEFINE x [ADD [VAR x] 1]]] [CONCAT "hi x is " [VAR x] " right now | "]]
"hi x is 0 right now | hi x is 1 right now | hi x is 2 right now | hi x is 3 right now | "
Numbers n' Vars || Arrays || Strings || Control flow || Meta || # || How do I start?