How to "comment-out" (add comment) in a batch/cmd?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
In Windows batch files, use REM to add a comment. Everything after REM on the same line is ignored by the command interpreter. The alternative is :: (double colon), which is technically a label that goes nowhere but is widely used as a comment because it is shorter and visually cleaner. Both approaches are single-line only. Batch has no native block comment syntax.
REM: The Official Comment Command
REM (short for "remark") is the documented, supported way to add comments in batch files. The command interpreter skips everything after REM on the same line.
REM works everywhere in a batch file: at the top level, inside IF blocks, inside FOR loops, and inside parenthesized code blocks. This universality is its primary advantage over ::.
Inline comments with REM
You can place REM after a command using &:
The & chains two commands on one line. The second command is REM, which does nothing. This is the closest batch scripting gets to an inline comment.
:: (Double Colon): The Practical Alternative
:: is technically a label with an invalid name. Because the interpreter cannot jump to it, it effectively does nothing. Developers adopted it as a comment syntax because it is shorter than REM and visually stands out more.
The visual clarity is real. In scripts with heavy commenting, :: creates a cleaner look than REM because it uses fewer characters and creates a more consistent left margin.
REM vs :: Comparison
| Feature | REM | :: |
| Official documentation | Yes, supported command | No, exploits label syntax |
| Works at top level | Yes | Yes |
Works inside IF/FOR blocks | Yes | Unreliable (can cause errors) |
| Works inside parenthesized groups | Yes | Can break the block |
| Inline after a command | Yes, with & REM | No |
| Performance | Slightly slower (parsed as command) | Slightly faster (skipped as label) |
| Visual clarity | Moderate | High |
The performance difference is negligible in practice. The real decision point is whether your comment appears inside a code block.
The :: Problem Inside Code Blocks
This is the most important thing to know about :: in batch scripts. Inside parenthesized blocks (which includes IF/ELSE, FOR, and multi-line grouped commands), :: can cause syntax errors or unpredictable behavior.
This works:
This can break:
The interpreter sometimes treats :: inside parenthesized blocks as a malformed label definition, which disrupts the parsing of the block. The behavior varies across Windows versions and depends on surrounding code. The safe rule: always use REM inside parenthesized blocks.
Commenting Out Code for Debugging
When you need to temporarily disable lines during troubleshooting, prefix them with REM:
Only Step 1 and Step 4 execute. Steps 2 and 3 are commented out but preserved in the script for easy re-enabling.
For multiple consecutive lines, REM is the only reliable approach:
Simulating Block Comments With GOTO
Batch has no multi-line comment syntax, but you can simulate it with a GOTO that skips a section:
The GOTO jumps to the :skip_comment label, bypassing everything in between. This is useful for temporarily disabling large sections of a script without adding REM to every line.
A cleaner version uses a descriptive label:
Using % Comments in Special Cases
Some developers use a variable expansion trick for end-of-line comments:
The %= and =% delimiters create an undefined variable name containing a space, which expands to nothing. This is a hack, not official syntax, and it fails if EnableDelayedExpansion interacts badly with the content. It is mentioned here for completeness, but & REM is more readable and reliable.
Best Practices for Batch File Comments
Script headers
Start every non-trivial batch file with a header block:
Section markers
Use comment blocks to separate logical sections:
Explain the "why," not the "what"
Common Pitfalls
Using :: inside IF, FOR, or parenthesized blocks. This is the most common batch commenting mistake. The interpreter can misparse :: as a label inside these constructs, producing cryptic errors. Always use REM inside code blocks.
Assuming batch supports block comments. Developers coming from C, Java, or Python expect /* */ or """ syntax. Batch has no equivalent. Use repeated REM lines or the GOTO skip pattern.
Forgetting & before inline REM. Writing set X=5 REM comment does not create a comment. It sets X to 5 REM comment. You need set X=5 & REM comment with the & command separator.
Over-commenting obvious code. Adding REM increment counter above set /a counter+=1 adds noise without value. Comment on the purpose and context, not the mechanics.
Leaving debug REM lines in production scripts. Commented-out code that stays in a script indefinitely creates confusion about whether it should be re-enabled or deleted. Clean up disabled code once the debugging session is complete.
Summary
REMis the standard, universally safe comment command in batch files. Use it by default, especially inside code blocks.::is a popular shorthand that is visually cleaner but breaks inside parenthesized blocks (IF,FOR, grouped commands).- For inline comments after a command, use
& REM comment text. - Simulate block comments with
GOTO :labelto skip large sections without prefixing every line. - Always use
REMinsideIF/ELSEandFORloops to avoid parsing errors. - Comment on purpose and context rather than restating what the code literally does.

