Commenting
Alright, let's talk commenting. We use comments to write messages for ourselves in the code, without breaking the code we've written.
From now on, you will see more comments, which make it easier, as you can look through the code and see what individual code sections do.
Comments are helpful for a few reasons
- Allow you to explain your code to other programmers or your future self
- Help with organization
- Simplify complex areas
Now, let's learn about the two types of comments:
Single-Line Comments
To write single-line comments, all you need to do is add a //, and you can write whatever you want.
You can write them after lines of code, or on their own lines of code.
You can not end a single-line comment, as it continues forever after //.
Here are some examples:
int x = 5;
x *= 2; // multiply x by 2
// print x
System.out.println(x);
Multi-Line Comments
We can also do multi-line comments, using /* and */.
We just specify where we want the comment to start with /*, and where we want it to end with */.
/*
List of things to do:
- add prints
- calculate values
*/
int x = 7;