Share via


What are the 14 Keywords of Small Basic?

In the Small Basic FAQ, it mentions there are 14 keywords:

What are the unique features of the Small Basic language?

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

==========

Of the 14 keywords, we'll cover 16 of them in this blog post:

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

==========

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 subRainyCount

    If Rainy = "y" Or Rainy = "Y" Then

       RainyCount = RainyCount + 1

    EndIf

EndSub

  

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:

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

And the Operator list:

And
Or

   

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!

Thanks!

   - Tall Basic Ed

Comments

  • Anonymous
    October 08, 2012
    Ed,thanks for your summary. And  I had copied it for further study.

  • Anonymous
    October 08, 2012
    you should have gone rid of the "THEN"- keyword. It would work fine without. "While" doesn't need it, and the interpreter always complains that I forgot it instead of directly putting it in...

  • Anonymous
    October 08, 2012
    So, maybe I'm missing something, but, given a total of 14 keywords, how are you able to showcase 16 of them?

  • Anonymous
    October 08, 2012
    Like Jay said, 16 out of 14 doesn't make sense.

  • Anonymous
    October 08, 2012
    I think "And" and "Or" are not the keywords but operators like "+", "-", and etc.

  • Anonymous
    October 09, 2012
    The 16 was a joke. I'll be more specific and add that in. Thanks!

  • Anonymous
    October 09, 2012
    Great work Ed! This is a big help for starters. I did not know that there is a keyword called "Step". Now I know it. I am your first lucky fan. :)

  • Anonymous
    October 13, 2012
    What about SELect on, DIMension etc and all those good things U could do with Qbasic?

  • Anonymous
    February 15, 2013
    I thought the joke was funny. Have a little humor folks.

  • Anonymous
    February 16, 2013
    Smilerg, well this isn't Qbasic, is it? =^) Small Basic is designed to keep it simple, teach you the basics of BASIC, and move you on to Visual Basic. Thanks for visiting!

  • Anonymous
    February 16, 2013
    John, thanks! Yeah, I think the joke was lost on them. They didn't understand it was a joke. And, as we all know, jokes are funnier when you explain them! =^) For example, jokes aren't actually as funny when you explain them... explaining a joke pretty much ruins it, as I just explained the joke about jokes.

  • Anonymous
    February 16, 2013
    Rene, that's an interesting perspective about the "THEN" keyword not being needed. Thanks for the feedback!

  • Anonymous
    May 15, 2013
    Thanks  for your summary. Helpful for me

  • Anonymous
    May 18, 2013
    Great, Carlos, I'm glad this is helpful!

  • Anonymous
    October 11, 2013
    i have homewor and its all about small basic how would you  create code for a variable, loop, turtle and draw shapes?

  • Anonymous
    March 23, 2014
    Elle, Sorry for the late answer, but we made resources that teach you all these things... Getting Started Guide: social.technet.microsoft.com/.../16059.small-basic-getting-started-guide.aspx Curriculum: social.technet.microsoft.com/.../16299.small-basic-curriculum.aspx  

  • Anonymous
    May 08, 2014
    I'm LOOKING FOR A PROGRAMING LANGUAGE THAT INCLUDES CODING TO CREATE GRAPHICS. SO FOR I ONLY SEE THE 14 COMMAND WORDS. DOES THIS MS SMALL LANGUAGE HAVE GRAPHICS CODING ?? PLEASE ADVISE THANK YOU

  • Anonymous
    May 08, 2014
    THE 14 KET WORDS DO NOT INCLUDE WORDS TO MAKE GRAPHIC ELEMINTS ? DAH  // THANJ YOU WHAT CURRENT FORM OF BASIC [ E.G. QBASIC DOES HAVE KEY WORDS FOR GRAPHIC EKEMENTS AND ALSO MUSICAL NOTES E.G THE  DISTONIC SCALE THANK YOU

  • Anonymous
    June 06, 2014
    Thanks for the obvious 14 commands and 2 operators. Most of these are exactly the same as the original 8 bit basic. What are the REST of the commands you wrote in? How do I print? Do an input? output? How do I write to a data file?  Save a data file? Change directories? In short, has anyone, anywhere written a translation dictionary from Basic to Small Basic? I've tried the tutorial that you provide a link to, and it is useless!  It doesn't cover what I need, and it doesn't give me a basic guide to the command structure.  All it does it give me a bunch of examples that DON'T do what I want, and leaves it to me to extrapolate from the examples. I DON'T HAVE TIME FOR THAT.  I have a program.  It's worked since 1987.  I just need to understand what to type in the place of "LPRINT" or "PRINT" to get the the programs to run in Windows7

  • Anonymous
    April 08, 2015
    Phil, that's right. Small Basic is an object-oriented language. It's not command oriented. So it doesn't have keywords for graphics. But it has many objects and methods that do graphics, including the Turtle Graphics object! Please follow the resources I linked to above in order to follow the tutorials and learn about all the capabilities!

  • Anonymous
    April 08, 2015
    Hate, Yes, that's the goal! We wanted to keep the very basic keywords and operators. As I mentioned above, Small Basic is an object-oriented language. You print with the WriteLine method in the TextWindow object. You can also print text into the GraphicsWindow. This aligns Small Basic closer to VIsual Basic than to the original BASIC, which is important to teach students professional languages, such as Visual Basic (there's even a Graduate button that turns your code into VB code for you to keep learning the new language), C#, and C++. It also helps for Java. The goal is to have a Basic and easy language to learn, but to also drive students toward professional programming as directly as possible. The tutorial is actually a library of many different lessons, that give a nice tour through many of the Small Basic objects. No. Nobody would write a translation dictionary from BASIC to Small Basic because Small Basic is an object-oriented language. Is the curriculum and getting started guide useless? Yes, if you're trying to use it to learn BASIC. But if you're trying to learn Small Basic, I haven't heard it called useless. Only useful. You don't replace LPRINT and PRINT. Those are commands. You use objects (TextWindow) and methods (WriteLine). It's not one for one. That's why it isn't "Small BASIC" and aligned with BASIC. It's "Small Basic" to align more with Visual Basic. For example, in Visual Basic, you would use the Console object: msdn.microsoft.com/.../aa309383%28v=vs.71%29.aspx You use the same Writeline method. So Small Basic maps toward that, replacing the Console object with the TextWindow object.

  • Anonymous
    April 08, 2015
    And VB6 uses MsgBox to speed things up a tad: msdn.microsoft.com/.../3cf7t4xt%28v=vs.110%29.aspx

  • Anonymous
    January 21, 2016
    hi this site is not what I am looking for. I have a piece on homework about what a 'for loop' and a 'While loop' are? but  I have no clue what they are!!! Please can someone help me?

  • Anonymous
    January 31, 2016
    EMS Master, the Forum is the fastest way to get answers: social.msdn.microsoft.com/.../threads So your homework is likely already due, but to answer your question, I previously put together some fantastic content for students that explains For and While loops... ...   Small Basic: For Loop Diagram blogs.msdn.com/.../small-basic-for-loop-diagram.aspx ... Example While Loop blogs.msdn.com/.../small-basic-while-loop-example.aspx ... Small Basic: Infinite For Loops blogs.msdn.com/.../small-basic-infinite-for-loops.aspx ... Small Basic For Loops: Control Variable Warning blogs.msdn.com/.../small-basic-for-loops-control-variable-warning.aspx ... Small Basic: Three Loop Counters blogs.msdn.com/.../small-basic-three-loop-counters.aspx ... History of the For Loop blogs.msdn.com/.../the-history-of-the-for-loop.aspx ... Small Basic: Goto Loops blogs.msdn.com/.../small-basic-goto-loops.aspx

  • Anonymous
    May 21, 2016
    hi I really like the fact that you added the conditional statement. however you need to write more about them

  • Anonymous
    June 20, 2016
    thanks!

  • Anonymous
    December 11, 2016
    cheers ma g

  • Anonymous
    March 17, 2017
    I would like to get my daughters primary school to teach Microsoft small basic. Can you help me in this matter?RegardsHoward Honey

  • Anonymous
    November 05, 2018
    Thnx so much