Developers often need to collaborate with other developers. Comments are an easy way for developers to write notes in the code and communicate with others. Comments are ignored by the computer; thus, they are also an easy way to tell the computer to not run certain lines of code. There are two ways to create comments:
- To comment out one line, place
//in front of a line of code. For example:
// This is a single-line comment.
- To comment out multiple lines at once, indicate the start of the comment with
/*and the end of the comment with
*/. For example:
/* This is a multi-line comment. This line is also part of the comment. */
To remove a comment (or uncomment a line), simply delete the
// for a single-line comment, or the
/* and the
*/ characters for the multi-line comment.
//in front of
Toast.makeText(this, "Welcome to Tic-Tac-Toe”, Toast.LENGTH_LONG).show(). After pressing the play button (►), check to make sure that
Welcome to Tic-Tac-Toedoes not show up on the screen.
- Delete the
//and instead, surround
Toast.makeText(this, "Welcome to Tic-Tac-Toe”, Toast.LENGTH_LONG).show()with
*/. Check that
Welcome to Tic-Tac-Toeis still not printed to the console after pressing the play button (►).
- Delete both
*/, and press the play button (►). Welcome to Tic-Tac-Toe should now be printed to the console. Throughout today’s puzzles, you will see various multi-line comments and
// PUZZLEcomments (like the one for Puzzle 2). These comments will guide us towards completing the Tic-Tac-Toe game, so be sure you understand how to comment and uncomment code.