Learning to program can feel like memorising grammar before you have said a single sentence. Small Basic was built to reduce that friction. It is a simple language with English keywords, and it lets you see the result of your code on screen within minutes. This article moves from a few lines of text output to loops, conditions, subroutines and arrays. Each idea comes with a short program and a drill. Along the way you will also practise the symbols that code relies on, such as brackets, quotes and the greater-than sign, so your keyboard gets ready at the same time as your thinking.
Your first program: printing text
The simplest program prints something to the screen. In Small Basic you do that with the TextWindow.WriteLine command. It writes one line of text to the text window and moves the cursor to the next line.
TextWindow.WriteLine("Hello, world!")
TextWindow.WriteLine("I am practising my typing today.")
Notice three things. The text you want to show sits inside double quotes. The command is followed by round brackets. You do not need a semicolon at the end of each line. On a US keyboard, the brackets are Shift with the 9 and 0 keys, and the double quote is Shift with the apostrophe key on the right side of the home row. Typing these symbols a few times in a row builds the muscle memory you will need for the rest of the article.
For a drill, write three lines that print your name, your favourite colour and a number. Type every line yourself rather than copying and pasting. If a quote or bracket is missing, read the line slowly from the end back to the start. That habit will save you a lot of time when your programs grow longer. Reading from the end is slower at first, but it trains you to notice a missing symbol before it causes confusion.
Loops: repeating work without repeating yourself
Instead of writing the same line five times, you use a loop. In Small Basic, a loop that starts with For ends with EndFor. The lines between them run again on every pass.
For i = 1 To 5
TextWindow.WriteLine("Line " + i)
EndFor
Here i is a counter. It starts at 1 on the first pass and reaches 5 on the last. The + sign joins the text and the number so the counter can be shown on screen. Small Basic does not require indentation, but indenting the lines inside the loop makes the structure easy to read, and readable code is much easier to fix later.
Change the loop so it runs from 1 to 10. Then change the text to “Round” and count how many lines appear. Small changes like these show you how the counter drives the loop. Before you run the program, predict what the output will be, then check whether you were right. Getting a prediction wrong is useful too, because it shows you exactly which idea needs another look.
Conditions: making a decision
Sometimes a program should behave differently depending on a value. For that you use If, Then, Else and EndIf.
score = 75
If score >= 50 Then
TextWindow.WriteLine("You passed.")
Else
TextWindow.WriteLine("Try again.")
EndIf
On a US keyboard, the greater-than sign is Shift with the period key, and the equals sign is on the top row next to 0. The >= pair therefore asks you to move between two keys in quick succession. That is a good skill to practise, because comparison symbols show up in almost every program you will ever write.
For a drill, change the score to 40 and then to 90 and run the program each time. After that, delete the Else part and keep only the If block. You should be able to explain, in one sentence, when the message appears. If you can do that, you have understood the idea of a condition. If your answer is no, go back to the drill and try the program with a few more values.
Subroutines: write it once, call it many times
If you need the same message in several places, place it inside a subroutine. A subroutine starts with Sub and ends with EndSub. You call it by writing its name followed by round brackets.
Sub SayHello
TextWindow.WriteLine("Hello!")
EndSub
SayHello()
SayHello()
This program prints the message twice, but the message itself is defined only once. If you later want to change it, you edit one place. Keep subroutine names simple and without spaces or accented letters, such as SayHello. Plain names are easier to type and easier to read. When you later read examples written by other people, you will be glad you kept the habit.
For a drill, add one more line to the subroutine and call it three times. Then move the call above the definition and see what happens. Reading the error will teach you that a subroutine has to exist before you call it.
Arrays: holding several values at once
Instead of creating a separate variable for each student’s grade, you can use an array. In Small Basic, you reach an element by putting a number in square brackets after the array name. You do not declare a size in advance. The array is created as soon as you assign a value to one of its elements.
grades[1] = 80
grades[2] = 65
grades[3] = 90
total = grades[1] + grades[2] + grades[3]
TextWindow.WriteLine("Total: " + total)
On a US keyboard, square brackets are plain keys to the right of the P key, so they need no Shift. That makes them easy to type once you know where they are. Notice how the index sits inside the brackets and the array name stays in front. Keep that picture in mind when you read code in other languages later.
For a drill, add two more grades, then calculate the average. Store the total in one variable, divide it by the number of grades, and print the result. Then try printing every grade with a loop, using the counter as the index.
Text length and a small project
Sometimes you need to know how many characters a piece of text contains. The Text.GetLength command returns that number. It is useful when a program needs to check that a name or a password is not too short.
name = "keyboard"
length = Text.GetLength(name)
TextWindow.WriteLine("Letters: " + length)
This program prints Letters: 8, because the word keyboard has eight characters. Spaces count too, so the text “touch typing” has twelve characters including the space. As a drill, join your first and last name with a space in a single variable, then print how long the full text is.
Now combine what you have learned. The program below uses a subroutine, a loop and text joining together.
Sub Greet
TextWindow.WriteLine("Welcome back!")
EndSub
Greet()
For i = 1 To 3
TextWindow.WriteLine("Practice round " + i)
EndFor
Run it, then change one line at a time: the message, then the loop count, then the subroutine call. Keep a note of each change and what it did, so you can see your understanding grow from one run to the next. After each change, explain to yourself why the output changed. Reading code carefully is as important as writing it, and experienced programmers spend much of their time doing exactly that.
Next step
Once small programs feel comfortable, the Small Basic course repeats these ideas over longer lessons. Keep your typing sharp at the same time by running the typing test a few times a week and watching your progress. If you want to see why typing well matters for anyone who writes code, read our article on why programmers should touch type.