Conditionals and Loops
The if statement
var food = "pizza"
if food == "pizza":
print("Yammi!")
end
The if else statement
var food = "sushi"
if food == "hamburguer":
print("Tasty!")
else:
print("Meeeh")
end
Chained conditionals
var x = 0
if x < 0:
print("You need more!")
elif x > 0:
print("You need less!")
else:
print("Correct!")
end
Nested conditionals
var x = 1
if x < 0:
if x < 10:
print("It is a positive single digit.")
end
end
For Loops
The for loop will iterate from one number to another or a list. It will go one by one by default, but you can specify the jump value.
-
For Loop with Step 1
for i=0 to 10:
print(i)
end
or
for i in range(0, 10):
print(i)
end
-
For Loop with Step 2
for i=0 to 10 step 2:
print(i)
end
-
For Loop over a List
for i in ['Iron Man', 'Spiderman', 'Black Widow']:
print(i)
end
While Loop
The while loop will loop while the condition is met.
var x = 0
while x < 10:
print(i)
var i = i + 1
end