u936293
u936293

Reputation: 16264

Comments not permitted after continuation character?

The following works fine:

if (  $a -eq 2 `
  -or $a -eq 3 )
  { write-host "Hi" }

but not the following:

if (  $a -eq 2 ` #...
  -or $a -eq 3 )
  { write-host "Hi" }

Why?

Neither does this:

if (  $a -eq 2 
  -or $a -eq 3 )
  { write-host "Hi" }

Upvotes: 1

Views: 89

Answers (1)

TheMadTechnician
TheMadTechnician

Reputation: 36322

The reason is that you are telling powershell to escape the next character when you use the backtick character. It can be used as a line continuation character if used as the last character of a line because it is then escaping the carriage return and turning it from a logical End-Of-Line marker and converting it into a literal carriage return that does nothing more but move to the text to the beginning of the next line. It will fail to act as a line continuation character if any character is placed after it on the line, not just comments. You can't even have whitespace after it in order for it to function as a line continuation character.

Upvotes: 5

Related Questions