ScripticXLearn programming visually
Platform
Problems
Community
Leaderboard
Learn
Docs
MiniScript+ basicsVariablesOperators and expressionsInput and outputConditions and decisionsLoopsStringsSums, counts, and extremaDigits of a numberDivisibility and prime numbersNumeric sequences and recurrencesNumber basesFunctions and parametersRecursion
Examples
Basic programsConditionsInput and outputLoopsAlgorithmsWorking with textDigit problemsBase conversionsFunctions and recursionEncode text with a key
What's newHelpContact
Loading…

Examples

MiniScript+

ExamplesMiniScript+
Fundamentals
Basic programsConditionsInput and output
Programming patterns
LoopsAlgorithmsWorking with textDigit problemsBase conversionsFunctions and recursionEncode text with a key
Examples/Loops

Loops

Counters, totals, countdowns, and repeated input implemented with MiniScript+ loops.

On this page
Count upwardSum from 1 to NCountdownProcess repeated inputTrace state

Loops repeat the same operation while a condition holds or across a known interval.

Count upward#

MS+counter.mspMiniScript+
1counter = 02​3WHILE counter < 54  PRINT counter5  counter = counter + 16END

Expected result: 0, 1, 2, 3, 4.

Sum from 1 to N#

MS+sum.mspMiniScript+
1n = 52total = 03​4FOR value FROM 1 TO n5  total = total + value6END7​8PRINT total

Expected result: 15.

Countdown#

MS+countdown.mspMiniScript+
1counter = 52​3WHILE counter >= 04  PRINT counter5  counter = counter - 16END

Expected result: 5, 4, 3, 2, 1, 0.

Process repeated input#

MS+three-values.mspMiniScript+
1total = 02​3FOR index FROM 1 TO 34  INPUT value5  total = total + value6END7​8PRINT total

Expected result: 6. Submit 1, 2, 3 at the three prompts, one value at a time.

Every WHILE loop must make progress toward a false condition. Otherwise it will run indefinitely.

Trace state#

In the sum example, the total becomes 1, 3, 6, 10, 15. Initialize it before the loop; putting total = 0 inside the body would discard the accumulated sum. FOR includes both bounds. Set n to 0: zero iterations leave the sum at 0. Read loops and sums and counts.

PreviousInput and outputNextAlgorithms

On this page

Count upwardSum from 1 to NCountdownProcess repeated inputTrace state