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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -