The comments written within the program is ignored and is not executed. So it can be used to prevent some code from execution when you comment it out.
Importance Of Comments In Programming
Importance of comments in programming is as follows:
- Comments in code give extra information about the code like some variable, function use, etc.
- Commenting code makes code more readable and easy to understand for the developers.
- Tricks used within the program can be explained within the comments.
- It can stop a block of code from execution if you don't want to execute for some case.
- Comments help to understand code when you refer it in future.
Note: Writing comments in code is highly recommended.
When you place 2 slashes // then the code or text of the current line is ignored until the next line.
Using comment to prevent execution
Commenting out code using a single-line comment. Uncomment the code below and run to understand.
When you need to comment out a large block of code then commenting code using single-line comment is quite burdensome. To comment out multiple lines of code use multi-line comment.
multi-line comment starts with /* and ends with */. The example below uses a multi-line comment for better understanding.
Using comment to prevent the execution