I often use :: to initiate a comment. Now I had a IF block and I found multiline :: comments do not work in *.bat files if they are in a IF-Block. I found this site https://www.robvanderwoude.com/comments.php and this explains a lot about comments in *.bat files.
normally comments are initiated by a REM command. as the site says... on each REM command the cmd interpreter will ignore the line but re-read the whole file to get the next line after the REM-line, and this will slow down the whole process.
but :: -comments will be interpreted as a invalid GOTO-Label and so the interpreter just jumps to the next line and will not re-read the file and is there for faster processed.
now I also hat a other idea which is not discussed on this site
to create comments with a false IF-Block
IF defined COMMENTBLOCK (
Write
Your multiline
comment here.
)
because the variable COMMENTBLOCK is not defined the interpreter will never look inside the block of the IF command and so it will just jump over the comments inside of the block.
now on this site the guy is talking about speed of a process. I think the interpreter will check the variable COMMENTBLOCK and since it is not defined read all lines until the end of the block and then go on with the process it will, as I think but not am sure of, not re-read the *.bat file as if I would use REM commands, and it would work inside of a IF or FOR block in opposite to :: comments which do not work in IF or FOR blocks if the comment is multiline.
now how can I measure the speed of a *.bat file to find the difference in speed between each method of comment? How can I be sure that...
IF defined COMMENTBLOCK (
Multiline
Comment
)
... is fast as
:: Multiline
:: Comment
and how can I prove that ...
REM Multiline
REM Comment
... will be slower than the other methods of commenting?
Such *.bat files are extremely fast ... the difference may is below a second the %time% variable shows me hours minutes seconds and hundreds of a second ... but to over jump such a comment does even seem to take less time ... so the result is really just a logical estimation at all.
also I do not have floppy disks to see what happens if the methods are used from floppy.
may the best would be if some one who knows it could explain what the interpreter does if a false undefined IF-Block appears ... does it act like false labels :: or REM? and what would may be a disadvantage of false IF-Blocks to create multiline comments inside of FOR and IF-Blocks?
Thanks in advance for your clarification...
UPDATE: the method with undefined variables as COMMENTBLOCK can not handle pipes | or closing brackets ) ...
IF defined COMMENTBLOCK (
)
|
This will fail!!!
)
the method with :: and REM can handle every thing including pipe |
:: |
REM |
.. but :: -comments can not be used inside of blocks as IF and FOR
a other strange method for multiline comments is to place two commands in one line as echo sometext & pause but instead of the pause command you need a invalid goto label :: and then add new lines with ^ at the end, this will need a blank line between every comment line and to keep the lines together each line must get a line break with ^
echo some command &:: ^
_^
Strange characters do work ^
_^
but quotes are sensitive, they must be even ^
_^
last line of comment
a other nice method to create multiline comments is to use %= comment =% lines...
%= multiline =%
%= comment =%
... this also has its drawback, %, !, %~ inside of comments will confuse the interpreter, strange characters can be escaped awkwardly %= %% ~f0 =%
see also the comments below for more information and thanks