Blog Post

Small Basic Blog
1 MIN READ

Algorithm Basics in Small Basic

NonkiTakahashi's avatar
NonkiTakahashi
Iron Contributor
Feb 13, 2019
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


Published Feb 13, 2019
Version 1.0
No CommentsBe the first to comment