Skip to content

Control flow

Inferno edited this page Jan 21, 2023 · 11 revisions

Control flow

compare

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

if

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"

loop

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']

try

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"

RETURN

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"

while

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 | "
Clone this wiki locally