1
$StartID = Read-Host -Prompt "StartID"
$StopID = Read-Host -Prompt "StopID"
$i = $StartID
do {
    Write-Host $startID
    Write-Host $StopID
    $i = ($StartId + 1)
} until ($i -gt $StopID)

The first problem is that after the statement $i = $startid + 1, the $i equals 11 and not 2. The second problem is that even though the until statement says that it should stop when $i -gt $stop the loop continues forever.

How do I get the $i to increase by 1 and not 10 and how do I stop the loop when $i -gt $stop.

0

1 Answer 1

4

Read-Promptreturns a string per default (this stackoverflow answer explains different ways for conversion). You've to convert/cast the string to a numeric value:

[int]$start = Read-Host -Prompt "Start"
[int]$stop = Read-Host -Prompt "Stop"

do {
   Write-host $start
   $start++
} until ($start -ge $stop)

Hope that helps.

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

Comments

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.