ExamplesAlgorithms
Algorithms
Classic MiniScript+ algorithms with traceable state and compact implementations.
On this page
These examples combine variables, conditions, and loops into complete algorithms.
Prime number test
prime.msp
n = 7divisor = 2isPrime = TRUEWHILE divisor < n IF n MOD divisor = 0 THEN isPrime = FALSE END divisor = divisor + 1ENDIF isPrime THEN PRINT "Prime"ELSE PRINT "Not prime"ENDFibonacci sequence
fibonacci.msp
count = 5first = 0second = 1FOR index = 1 TO count PRINT first next = first + second first = second second = nextENDGreatest common divisor
Euclid's subtraction method repeatedly reduces the larger number.
gcd.msp
first = 12second = 8WHILE first != second IF first > second THEN first = first - second ELSE second = second - first ENDENDPRINT firstMaximum of three values
maximum-three.msp
first = 3second = 7third = 5maximum = firstIF second > maximum THEN maximum = secondENDIF third > maximum THEN maximum = thirdENDPRINT maximum