Concept Explanation: Comments and White Space

Printer-friendly version

RobotC is a free-form programming language. This means that when you write a program, multiple spaces, tabs, and line returns are ignored by the NXT. This allows us to use these ignored structures to format our program and make it easier to read. If wanted, we could put all of our commands on one line. Here is what the above example program would look like if we did:

  1. task main{eraseDisplay();nxtDisplayString(1,"Hello World");wait1Msec(2000);}

So in the interest of making our code easier to read, we put each command on new line.

Another thing that is ignored by the compiler is comments. Comments are essentially notes that we leave inside the program.  Most complex programs are created over the course of weeks or months. While you can write commands in a way that is easy to read, it can really help to have a quick explanation of what is going on. It is recommended that you add comments as you write your program.

There are two types of comments:

  • Single line – uses two forward slashes at the start of a line. “ // This is a comment ”
  • Multi line – uses a “slash star” to encapsulate your comment. “ /* This is a comment */ “