powershell - while loop not terminating when user presses "n" -
i'm trying create menu using while
loop. want menu run till user presses "n" or "n".
$menuchoice while ($menuchoice -ne "n" -or $menuchoice -ne "n") { write-host "run again? y/n " read-host $menuchoice }
the problem that, runs whether press "n" or "y".
do need declare value $menuchoice
?
you need assign output of read-host
$menuchoice
:
# initial value (in case run more once) $menuchoice = $null # comparison not case-sensitive while ($menuchoice -ne 'n') { $menuchoice = read-host 'run again? [y/n]' }
Comments
Post a Comment