while loop with or statement

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 2 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
Alienxxl
Posts: 1
Last visit: Sun Jan 28, 2024 10:47 pm

while loop with or statement

Post by Alienxxl »

I have problem with using 2 conditions in while loop at my code.
condition after "or" statment is ignored

while (($log_in -ne $NULL) -or ($log_in -eq "JA99878"))
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: while loop with or statement

Post by jvierra »

That kind of statement never needs to be tested for null.

while ($log_in -eq 'JA99878')

No need for null test as it only runs when equal and will quit on not equal or null.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: while loop with or statement

Post by Alexander Riedel »

[Topic moved by moderator. Please always post in the forum best suited for your question]
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 2 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked