Loops

Loops repeat a block of code and are the first place where algorithmic thinking becomes visible.

WHILE Loop

A WHILE loop runs as long as a condition is true.

X = 0
WHILE X < 3
  PRINT X
  X = X + 1
END

How it works

  • The condition is checked before each iteration
  • If true → the loop runs
  • If false → the loop stops

Example Explained

X = 0        # start
WHILE X < 3   # check condition
  PRINT X     # output
  X = X + 1   # update
END

Output will be:

0
1
2

Infinite Loops

If the condition never becomes false, the loop would run forever. ScripticX stops suspicious executions and reports a runtime error instead of freezing the page.

WHILE true
  PRINT "Hello"
END

Use the step debugger to check whether the variable inside the loop actually changes.

Common Mistake

Forgetting to update the variable inside the loop.

X = 0
WHILE X < 5
  PRINT X
END

This can cause an infinite loop