While loop and powershell

I have made a loop like this

$end = Read-Host "Type"
if ($end -eq 1)
{
Funtion1
}
elseif ($end -eq 2)
{
Function2
}
else
{Write-Host "The end"}
} while ($end -eq 1)

My problem is that now this loop is working when i type number 1. But it should work with 1 and 2.  -gt is is not an option because user might type also something else than text there. Im very new with PS but this cant be very difficult.

Thanks in advance :)
Timo
thaapavuoriAsked:
Who is Participating?
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Just use
    while ($end -eq 1 -or $end -eq 2)
instead.
0
 
soostibiCommented:
The 'do' is missing from the beginnig:

do{
$end = Read-Host "Type"
if ($end -eq 1)
{
Funtion1
}
elseif ($end -eq 2)
{
Function2
}
else
{Write-Host "The end"}
} while ($end -eq 1)
0
 
thaapavuoriAuthor Commented:
It was my typo. There is "do" in my real script. The problem is that this loop will continue forever as it should if I type 1 but it should continue also if I type 2. Now this loop will stop after one circle if I type 2.

Thanks.

Timo
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.