Dimlo powershell do while loop burp.

Soldato
Joined
8 Mar 2005
Posts
3,619
Location
London, UK
Being a being a bit of a cack-handed thicko here with a do loop with two conditions.
Code:
        $Timer = get-Date
        do
        {
        
        $Codeexecutedsuccessfully = 0
        <CODEBLOCK>
        $Codeexecutedsuccessfully = 1

        }
        while (((Get-Date).AddMinutes(-1) -le $Timer) -or ($Codeexecutedsuccessfully -eq 0))
My expectation is that the loop will break if either condition becomes false. However, the second condition is seemingly never met and the codeblock simply repeats for 60 seconds and meets the first condition.

ta, Paul.
 
Caporegime
Joined
18 Oct 2002
Posts
29,491
Location
Back in East London
The opposite. Both conditions must be true for the loop to continue looping. It is "while" after all. :)

If you really dumb it down and do/think of it like this:

Code:
do {
    write "hello"
} while($TRUE -AND $FALSE)

vs
Code:
do {
    write "hello"
} while($TRUE -AND $TRUE)

You will see the difference very easily.
 
Back
Top Bottom