⌘K

Control Flow

Updated 16 Mar 2026

if / else if / else

if $score >= 100:
    send "&6Legend rank achieved!" to player
else if $score >= 50:
    send "&eHalfway there!" to player
else:
    send "&7Keep going." to player

while

Loops while the condition is true. Stops automatically after max-while-iterations.

set $i = 0
while $i < 5:
    send "Tick $i" to player
    set $i = $i + 1

for (range loop)

for $i from 1 to 10:
    send "Count: $i" to player

for $i from 0 to 100 step 10:
    send "$i%" to player

for $i from 10 to 1 step -1:
    send "$i..." to player

for each

set $items = "sword,bow,shield"
for each $item in $items:
    send "Item: $item" to player

repeat times

repeat 5 times:
    give player cooked_beef 1

repeat until

set $hp = 1
repeat until $hp >= 20:
    set $hp = $hp + 1
send "Healed to $hp" to player

switch / case / default

switch $rank:
    case "admin":
        give player command_block 1
    case "vip":
        give player gold_ingot 5
    default:
        give player bread 2

break and continue

for $i from 1 to 100:
    if $i == 42:
        break
    if $i % 2 == 0:
        continue
    send "Odd: $i" to player