In the Small Basic FAQ, it mentions there are 14 keywords:
Of the 14 keywords, we'll cover 16 of them in this blog post:
If, Then, EndIf
If (Clock.Hour < 12) Then TextWindow.WriteLine("Good Morning World")EndIf
We can shorten two if..then..endif statements to be just one by using a new word, else.
If we were to rewrite that program using else, this is how it will look:
If (Clock.Hour < 12) Then
TextWindow.WriteLine("Good Morning World")
Else TextWindow.WriteLine("Good Evening World")
If (i < 25) Then
For, To, EndFor
For..EndFor is, in programming terms, called a loop. It allows you to take a variable, give it an initial and an end value and let the computer increment the variable for you. Every time the computer increments the variable, it runs the statements between For and EndFor.
This program prints out numbers from 1 to 24 in order:
For i = 1 To 24
But if you wanted the variable to be incremented by 2 instead of 1 (like say, you wanted to print out all the odd numbers between 1 and 24), you can use the loop to do that too.
For i = 1 To 24 Step 2
The While loop is yet another looping method, that is useful especially when the loop count is not known ahead of time. Whereas a For loop runs for a pre-defined number of times, the While loop runs until a given condition is true. In the example below, we’re halving a number until the result is greater than 1.
number = 100
While (number > 1)
TextWindow.WriteLine(number) number = number / 2
A subroutine is a portion of code within a larger program that usually does something very specific, and that can be called from anywhere in the program. Subroutines are identified by a name that follows the Sub keyword and are terminated by the EndSub keyword. Below is a program that includes the subroutine and calls it from various places.
TextWindow.Write("Enter your name: ")
name = TextWindow.Read()
TextWindow.Write(name + ", the time now is: ")
If percentage >= 75 Then
TextWindow.WriteLine("The student’s grade is A.")
ElseIf percentage < 75 And percentage >= 60 Then
TextWindow.WriteLine("The student’s grade is B.")
ElseIf percentage < 60 And percentage >= 35 Then
TextWindow.WriteLine("The student’s grade is C.")
TextWindow.WriteLine("The student’s grade is D.")
If Rainy = "y" Or Rainy = "Y" Then
RainyCount = RainyCount + 1
Why are there 16 Keywords instead of 14?
Okay, so that was a bit of a joke. Sorry if it was lost on you. Usually when you say/read/hear "Of the X items, we'll cover Y of them..." the Y number is smaller than the X number, not larger.
"And" and "Or" are actually Operators, and they don't count as the Keywords.
So the Keyword list looks like this:
And the Operator list:
If you'd like to write up some short explanations of some of those keywords, I'll add your explanations above the examples. Just leave the suggested text in the comments!
- Tall Basic Ed