Windows OS

How to Add Comment in Command Prompt

Comments are the human-readable textual description of the code placed inside the program. The use of commenting in the code helps to maintain code and remove bugs easier and faster. It also assists the other developers in getting to know about the functionality of someone else code.

In this write-up, we are going to learn to:

    • Add single line comments in Command Prompt
    • Add Multiple line comments in Command Prompt

Let’s go through each of the mentioned methods, one by one!

Add Single Line Comments in Command Prompt

REM” command and the “:: (Double colon) are used to add the single line comments. REM is the short form of “Remarks”. It is the built-in command prompt utility of Windows.

Example 1: Adding Single Line Comments Using REM Command

In order to add a single line comment, first of all, launch a text editor or an IDE of your choice. In our case, we will open the text editor and write out the following code, which also contains a comment because of the REM command:

@echo off
echo single line comments
REM echo hello world
pause

 

Save the file with the “.bat” extension on the system and open it in command prompt:


As you can see that the single line of code was commented and is not displayed as output.

Add Single Line Comments Using “::” Double Colon

You can also comment in a single line by using the “::” (Double colon), as provided below:

@echo off
echo single line comments
:: echo hello world
pause

 

Output

Add Multiple Line Comments in Command Prompt

If you want to add multi-line comments, then it is required to use the “REM” command more than once.

For instance, add REM at the start of multiple lines to convert it into comments .and save the file with “.bat” extension:

@echo off
echo Multi-line comments
REM echo hello world
REM echo hello world
REM echo hello world
REM echo hello world
pause

 

Then, open it in the command prompt:


As you can see the multiple lines of code were commented and did not display in the CMD console.

Conclusion

The comments can be added to the CMD by using the “::” double colon and “REM” command. To do so, create a file using Notepad or IDE and add the required code. Then, add comments using the double colon or REM command and save the file with the “.bat” extension. This manual has provided the solution to single or multiple add the comments in Command Prompt.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.