Reputation:
I am trying to write a script that counts down any number a user puts in.
Write-Host "$Value1"
[int]$Value1 - [int]1
do {
$outputString = read-host
$outputString - [int]1
}
until ($outputstring=0)
$Value1
defines the number a user puts in. It seems to me that the initial value gets subtracted by 1, and after that the $outputString
should take the read-host information and subtract 1 untill it reaches 0.
At this point in time the only output I get is the Write-Host "[int]$Value1 - [int]1
", and the output subtracted by 1. However it does not loop untill it reaches 0.
Any way to fix this problem ?
Greetings
Upvotes: 1
Views: 4052
Reputation: 126852
How about this?
do {
$outputString = read-host enter a number
} while ($outputstring -notmatch '^\d+$')
if($outputstring -gt 0)
{
$outputstring..0 | ForEach-Object{
$_
Start-Sleep -Milliseconds 250
}
}
Upvotes: 1
Reputation: 72660
try :
do {
$outputString = read-host
$outputString -= [int]1
}
until ($outputstring -eq 0)
First, the egal operator is -eq
and not =
Second, you need to assign value to $outputstring
if you want it to break the loop :
$outputString -= [int]1
$outputString = $outputString - [int]1
Upvotes: 1