ScripticXLearn programming visually
Platform
Problems
Community
Leaderboard
Learn
Docs
BasicsVariablesLoopsInput / Output
Examples
BasicsLoopsConditionsAlgorithms
What's newHelpContact
Loading…

Documentation

MiniScript+

DocumentationMiniScript+
Getting started
MiniScript+ basics
Language basics
VariablesLoopsInput and output
Documentation/Loops

Loops

Repeat instructions safely with WHILE and FOR loops in MiniScript+.

On this page
WHILE loopsFOR loopsChoose the right loopAvoid infinite loopsNested loops

Loops repeat a block of instructions. They are useful for processing a sequence, validating input, or running a calculation several times.

WHILE loops#

A WHILE loop repeats while its condition remains true.

MS+MiniScript+
1counter = 02​3WHILE counter < 34  PRINT counter5  counter = counter + 16END

The output is:

TXTPlain text
102132

The loop has three parts:

  1. initialize the state before the loop;
  2. check a condition before every iteration;
  3. update the state inside the loop.

FOR loops#

Use FOR when the start, end, and step are known in advance.

MS+MiniScript+
1FOR number = 1 TO 52  PRINT number3END

Add STEP to change the increment:

MS+MiniScript+
1FOR number = 10 TO 0 STEP -22  PRINT number3END

Choose the right loop#

SituationRecommended loop
A known number of repetitionsFOR
Repeat until a condition changesWHILE
Walk through a numeric intervalFOR
Validate repeated user inputWHILE

Avoid infinite loops#

An infinite loop never makes its condition false.

MS+MiniScript+
1counter = 02WHILE counter < 53  PRINT counter4END

The update is missing

The example never changes counter. Add counter = counter + 1 inside the loop before running it.

Nested loops#

A loop may contain another loop. Use indentation to keep the structure readable.

MS+MiniScript+
1FOR row = 1 TO 32  FOR column = 1 TO 33    PRINT row * column4  END5END

Nested loops can perform many operations, so check the expected number of iterations before using them with large ranges.

PreviousVariablesNextInput and output

On this page

WHILE loopsFOR loopsChoose the right loopAvoid infinite loopsNested loops