Algorithm Basics in Small Basic
Published Feb 12 2019 05:33 PM 1,067 Views
Iron Contributor
First published on MSDN on Dec 29, 2016

Authored by Nonki Takahashi


Algorithm is combinations of code patterns.  Today, I'd like to introduce three basic code patterns.  I also wrote a sample program for this blog: LMR321 .

Sequence


Sequence of statements is the simplest pattern of code.  But sometimes the order of statements becomes very important.

Following two code blocks show the different results.
Turtle.Move(100)  ' move first
Turtle.Turn(90)
Turtle.Turn(90)  ' turn first
Turtle.Move(100)

Loop


In a program, we sometimes need to repeat something.  We can also write same lines of code, but a loop makes it simpler.  Following two code blocks show the same results.
TextWindow.WriteLine("Hello World!")
TextWindow.WriteLine("Hello World!")
TextWindow.WriteLine("Hello World!")
TextWindow.WriteLine("Hello World!")
For i = 1 To 4
TextWindow.WriteLine("Hello World!")
EndFor

Selection


There are some cases we'd like to change doing with conditions such as input data or current status.  We can do this kind of selection with If statement like following code.
If Turtle.Y < yCenter Then
TextWindow.WriteLine("UPPER")
Else
TextWindow.WriteLine("LOWER")
EndIf

See Also


Version history
Last update:
‎Feb 12 2019 05:33 PM
Updated by: