0

I'm not sure what the issue is, but I'm trying out a super basic for loop in PowerShell and I keep getting errors. Here is my loop:

for ($x = 1: $x -le 5: $x++) {

Write-Host $x

}

I get the error message: 1: : The term '1:' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Can I not use 1? Whats the issue?

1
  • 3
    : -> ; or function 1: {"1`n2`n3`n4`n5"} Commented Nov 13, 2016 at 17:10

1 Answer 1

3

What he is trying to say, you have a typo, it should be:

for ($x = 1; $x -le 5; $x++) {

Write-Host $x

}
Sign up to request clarification or add additional context in comments.

1 Comment

Yep, this was the issue. The online book I'm using doesn't have great resolution, so I saw : instead of ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.