Comments

Beginner Level Tutorial

What you will learn

What comments are and how they are used in your program.

What are comments?

Comments are a way of providing notations to your code. This is really helpful as it means you can add descriptions to your code explaining what is happening. Take a look at this very simple program.

score as integer = 0

do print ( score ) sync ( ) loop

The code declares a variable named score, assigns it a value of 0 and then performs a do loop, continually printing the value of score to the screen.

Let's return to the program, although this time with comments added.

// create a variable called score that will hold the score for the game
score as integer = 0

// loop round do // print the value of score to the screen print ( score )
// update the screen sync ( ) loop

The additional lines all begin with the characters //. This indicates to the program that we're leaving a comment on this line. Anything that follows it is ignored by the program. It's simply there as a mechanism for the programmer to provide more information about what is taking place.

To add a comment to your code start the line with // and enter useful information.

Other ways of adding comments

There are two alternative ways of adding single line comments, by using the keywords rem and `, as shown in this program.

rem create a variable called score that will hold the score for the game
score as integer = 0

` loop round do rem print the value of score to the screen print ( score )
` update the screen sync ( ) loop

Using blocks with comments

There may be occasions when you want to comment out a block of code or perhaps write a series of lines without wanting to use a single line comment marker. If this is the case you can use the keywords remstart and remend and /* and */. Here's a modification to the previous program with the inclusion of these new keywords.

// create a variable called score that will hold the score for the game
score as integer = 0

remstart player1 as integer = 0 player2 as integer = 0 remend
` loop round do rem print the value of score to the screen print ( score )
/* anything included within this section is a comment */
` update the screen sync ( ) loop

Any lines between remstart and remend are treated as comments. The same is also true of lines between the /* and */.

Conclusion

Comments are really simple to add into your program and will prove to be very useful in the long term. It's a good idea to get into the habit of commenting your code. In the short term it may not seem to be so helpful, particularly when dealing with small programs, however, as the complexity and size of your programs increase it undoubtedly becomes harder to manage. The addition of many comments in your code will prove to be useful reminders and explanations of how parts of your program work.