Tutorial Comments

From Monster Wiki

Jump to: navigation, search

Comments

There are three kind of comments in Monster. The two first should be familiar to C/C++ users:

// line comment: ignore the rest of the line

/* block comment: ignore a block of text that
   can span multiple lines */

/+ nested comments: ignore blocks of text, including other:
   // line comments
   /* block comments */
   /+ nested comments +/
   /+ You /+ can /+ nest /+ these /+ as +/ deep +/ as +/ you +/ like +/
+/

Commenting out code

Comments are completely ignored by the compiler - which means you can put anything you want inside them. A common use for comments (beside writing comments!) is to disable parts of the code which are not in use. For example:

import io;
 
writeln("Print this message");
//writeln("Ignore this line");
 
/*
writeln("Ignore");
writeln("all of this");
*/
writeln("and print this");

Output:

Print this message
and print this

Nested comments are particularly useful for this, since they will work even if the comment block contains other nested or block comments.