Using Liberty Basic

Want to learn to program using Liberty Basic? Already programming in Liberty Basic but want to learn more? Follow this experienced programmer (Java) as he teaches himself this wonderful programming language.

 

Monday, April 24, 2006

Commenting Your Code

As I am sure you are aware, it is extremely recommended for you to comment the code you write (both so that others can understand your code more easily, and also so that you can make sense of your own code more quickly when you come back to it after a break of more than a couple of months).

So, how do you comment your code in Liberty Basic? It's simple, all you have to do is prefix your comment with an apostrophe ('). If your comment spans multiple lines, make sure each line has it's own apostrophe to indicate the start of the comment on that line.

Let's demostrate this by way of example. How about we add some comments to the "Hello World" program we created in the last post. Here is what our new version of the program might look like.

' =================================
' Simple Hello World Program
' =================================
' Author: Eddie Meyer
' Date: 24th April 2006

print "Hello World!"
end


Note: A comment doesn't have to start at the beginning of a line. The following comment is equally valid.

print "Hello World!" ' This is a comment.
end


Note: In this second example, since the comment occurs after the print command, the print command will still execute. Had the apostrophe been placed before the print command, the print command would become part of the comment and would therefore not execute.

That's it. Now we don't have any excuse not to comment the code we write. :-). I wonder what the next post might be about. Oh well, we'll have to wait and see.

Eddie

2 Comments:

  • What about REM statement. This also give the same effect with apostrophy.

    Bear

    By Anonymous Anonymous, at 2:46 AM  

  • Good point. Yes, REM statements can also be used to comment your code. Here is an example...

    REM This is a comment.

    Thanks Bear.

    Eddie

    By Blogger Edward Meyer, at 6:55 AM  

Post a Comment

<< Home