Small Basic: The 14 Keywords

Small Basic: The 14 Keywords

Please add information to explain each keyword.

The Small Basic FAQ mentions there are 14 keywords in the language:

What are the unique features of the Small Basic language?

  • Size
    The Small Basic language consists of just 14 keywords.

==========

Here are the 14 Keywords:

Else
ElseIf
EndFor
EndIf
EndSub
EndWhile
For
Goto
If
Step
Sub
Then
To
While

And the 2 Operators:

And
Or

Within Small Basic a keyword is shown in the intellisense with this keys symbol:
 

==========

Examples...

If, Then, EndIf

If (Clock.Hour < 12) Then
  TextWindow.WriteLine("Good Morning World")
EndIf

Else

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")
EndIf

Goto

If (i < 25) Then
  Goto start
EndIf

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
  TextWindow.WriteLine(i)
EndFor

Step

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
  TextWindow.WriteLine(i)
EndFor

While, EndWhile

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
EndWhile

Sub, EndSub

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.

PrintTime()
TextWindow.Write("Enter your name: ")
name = TextWindow.Read()
TextWindow.Write(name + ", the time now is: ")
PrintTime()
 
Sub PrintTime
  TextWindow.WriteLine(Clock.Time)
EndSub

And, ElseIf

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.")
Else
  TextWindow.WriteLine("The student’s grade is D.")
EndIf

Or

Sub RainyCount
  If Rainy = "y" Or Rainy = "Y" Then
    RainyCount = RainyCount + 1
  EndIf
EndSub
Leave a Comment
  • Please add 5 and 5 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Ed Price - MSFT edited Revision 12. Comment: minor edit

  • Ed Price - MSFT edited Revision 13. Comment: Lost the code blocks.

  • Carsten Siemens edited Revision 10. Comment: fixed typo

  • Ed Price - MSFT edited Revision 9. Comment: Minor grammar.

  • litdev edited Revision 6. Comment: typo

  • litdev edited Revision 5. Comment: using Small Basic code formatter

  • Nonki Takahashi edited Revision 4. Comment: Added intellisense keys symbol image  

  • gungan37 edited Revision 3. Comment: Minor grammatical changes

  • Ed Price - MSFT edited Revision 1. Comment: I removed the "Ease of use" bullet. The reason is that the "What are the unique features" section was meant as a quote from the FAQ. So I moved the "Ease of Use" bullet over to a new article that lists out the unique features: social.technet.microsoft.com/.../14114.the-unique-features-of-the-small-basic-language.aspx

  • gungan37 edited Original. Comment: Added "Ease of Use"

Page 1 of 1 (10 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • A great reference for SB programmers, thanks!

  • A great reference for SB programmers, thanks!

  • gungan37 edited Original. Comment: Added "Ease of Use"

  • Ed Price - MSFT edited Revision 1. Comment: I removed the "Ease of use" bullet. The reason is that the "What are the unique features" section was meant as a quote from the FAQ. So I moved the "Ease of Use" bullet over to a new article that lists out the unique features: social.technet.microsoft.com/.../14114.the-unique-features-of-the-small-basic-language.aspx

  • gungan37 edited Revision 3. Comment: Minor grammatical changes

  • Thanks for the grammar fixes, gungan! Every bit helps!

  • Nonki Takahashi edited Revision 4. Comment: Added intellisense keys symbol image  

  • litdev edited Revision 5. Comment: using Small Basic code formatter

  • litdev edited Revision 6. Comment: typo

  • This article has been highlighted in this week's "Top Contributors" Wiki Ninja blog : blogs.technet.com/.../top-contributors-first-of-2013-windows-trust-migration-agudlp-admt-small-basic-forums-help-active-directory-lync-server-2013-and-more.aspx

  • Ed Price - MSFT edited Revision 9. Comment: Minor grammar.

  • Fun...although it is not as fast as surfing...I was delighted to make the text window  do what I commanded...here is my code that writes the designated text...and...changes both the background and forground colors.Very Fun and exciting. Thanks for the lesson sets and interface....TextWindow.WriteLine("Hello Mr. McKnight. My Bad, I mean to say")

    TextWindow.BackgroundColor="Cyan"

    TextWindow.ForegroundColor="Black"

    TextWindow.WriteLine("Hello Steven")

    TextWindow.WriteLine("How are you at present?")

  • Carsten Siemens edited Revision 10. Comment: fixed typo

  • Ed Price - MSFT edited Revision 12. Comment: minor edit

  • Ed Price - MSFT edited Revision 13. Comment: Lost the code blocks.

Page 1 of 1 (15 items)