Comments
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.
Working Together
- Type
//
in front ofToast.makeText(this, "Welcome to Tic-Tac-Toe”, Toast.LENGTH_LONG).show()
. After pressing the play button (►), check to make sure thatWelcome to Tic-Tac-Toe
does not show up on the screen. - Delete the
//
and instead, surroundToast.makeText(this, "Welcome to Tic-Tac-Toe”, Toast.LENGTH_LONG).show()
with/*
and*/
. Check thatWelcome to Tic-Tac-Toe
is still not printed to the console after pressing the play button (►). - Delete both
/*
and*/
, 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// PUZZLE
comments (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.