-
Notifications
You must be signed in to change notification settings - Fork 3
FlowControl
There are some commands in MeowScript that make it possible execute code on some conditions or in a specific way.
if executes code if a given expression equals to 1.
if(something == something) {
do something
}
The curly braces and the expression has t be on the same line!
Checks if the last if in the current scope failed (aka did not execute) and executes something if the check succeeds.
if(1 == 2) {
print "I think the universe is wrong..."
}
else {
print "nevermind..." # gets executed!
}
A combination of else and if.
Executes something if the last if fails and a given expression equals to 1.
This can be chained as well.
if(1 + 1 == 3) { # fails
print "math is wrong"
}
elif(1 * 1 == 1 + 1) { # fails
print "math is still wrong"
}
elif(11 - 1 == 10) { # executes!
print "yaay math is not wrong!"
}
else { # gets ignored
print "huh??"
}
Execute it's body while the given expression equals to 1.
new counter 5
while(counter != 0) {
print counter
counter = counter - 1
}
This will output:
5
4
3
2
1
Iterates through a given value and sets a variable based on the iteration each time the loop runs.
for <var> in <value> {
}
for i in "Hello" {
print i
}
This loops over each character in the given string. Output:
H
e
l
l
o
for i in 4 {
}
This will run the body setting i starting with 0 and ending with 3.
Output:
0
1
2
3
for i in [1,"2",[3,4]] {
print i
}
Loops over every element of the list beginning at the front.
1
2
[3,4]
The command continue will end the current run of the loop and start a new one right away.
Example:
for i in 10 {
if(i % 2 == 0) {
continue
}
print i
}
This will output all even numbers from 0 to 9:
0
2
4
6
8
Quits a loop, not allowing any further iterations or executions of the loop in general.
new inp ""
while(true) {
inp = {input("> ")}
if(inp == "q") {
print "exit!"
break
}
}
Possible output:
> hi
> huh
> q
exit!