Core Language
Control Flow
if / else if / else, while, for-in, break, continue, and return. No parentheses required around conditions.
New to coding?
Copy the examples exactly first. Run them. Then change one number or word and run them again. You are not expected to memorize the command lists.
1
if / else if / else
Try this code
if score >= 90 { print "A"; }
else if score >= 80 { print "B"; }
else if score >= 70 { print "C"; }
else { print "F"; }2
while
Try this code
i = 0;
while i < 10 {
print i;
i = i + 1;
}3
for-in
Iterates lists directly, or numbers via range(). Iterating a dict walks its keys.
Try this code
for name in ["alice", "bob", "carol"] {
print name;
}
for i in range(5) { print i; } // 0 1 2 3 4
for i in range(2, 10) { print i; } // 2..9
for i in range(0,10,2) { print i; } // 0 2 4 6 8
user = {"name": "Ada", "role": "admin"};
for key in user { print "{key} = {user[key]}"; }4
break and continue
break exits the innermost loop only; continue skips to the next iteration.
Try this code
i = 0;
while i < 10 {
i = i + 1;
if i % 2 == 0 { continue; }
if i > 7 { break; }
print i; // 1 3 5 7
}