how to program
HOW TO PROGRAM . IT - learn how to program - online interactive programming tutorial and programming course
Line Comments

Lesson 02: Single line comments are an easy way to comment and document your program. Explaining what is going on in your program is important for maintenance purposes, it helps you remember what is going on either if you or someone else revisits and needs to change, improve, support, fix, port (migrate to another environment) your program in the future.

Single line comments start with // and everything to the end of the line is ignored and treated just as a comment. As such, single line comments can appear on their own lines, or after some real code on the same line.

The following code demonstrates some examples of single line comments...

Program Code:

The last comment also demonstrates the idea of "commenting out" real code so that it does not get run. This might be better than deleting the code, since it is easy to remove the comments to let the code run again at a later time.

The above example also demonstrates the use of line spaces, to split up the program so that it is more easily read.


1. Comment out the "Hello World" line
2. Then get the "Hello World" line working again by removing the comment
3. Get the "Hello Universe" line working by removing the comment

To return to previous page click here

by running the tutorial programs on this site, you are agreeing to our terms and conditions (please check these first).
Thu 27 Jan 2022 web design | login © 2022 Abstract Worlds Ltd