Home > Blockchain >  While loop continues running even though it shouldn't
While loop continues running even though it shouldn't

Time:10-25

I'm creating regression using a while loop and some if statements in order to automate SQL testing, and everything seems to be functioning properly except for some reason when the $Phase is set equal to 4, (which should break the loop), it seems to run again, resetting the $Phase variable. There is no code in the "SQLQueryKafkaTesting" Function that should be affecting the $Phase or $Choice values except for this loop.

if ($Global:Dashboard -eq "KafkaDashboard_Headless") {
        while ($Phase -le 3) {
            $Choice  
            # max amount of choices for phase 1 (CDC-DB) exceeds here
            if ($Phase -eq 1 -and $Choice -gt 0) {
                SQLQueryKafkaTesting 2 0
            }
            # make sure we loop through all the choices for phase 2 (CDC-Tables), here 2 choices is the upper-bound exclusive
            if ($Phase -eq 2 -and $Choice -lt 2 ) {
                SQLQueryKafkaTesting 2 $Choice
                
            }
            # when there are no longer any phase 2 choices, go to next phase
            elseif ($Phase -eq 2 -and $Choice -ge 2) {
                SQLQueryKafkaTesting 3 0
            }
            # make sure we loop through all the choices for phase 3 (Diffs), here 2 choices is the upper-bound exclusive
            if ($Phase -eq 3 -and $Choice -lt 2 ) {
                SQLQueryKafkaTesting 3 $Choice
                
            }
            # phase 3 is the last phase, so once there are no more choices, we can break the loop
            elseif ($Phase -eq 3 -and $Choice -ge 2) {
                $Phase = 4
            }
        }
    }

CodePudding user response:

Solved, needed to call the SQLQueryKafkaTesting in a seperate function instead of within itself, allowing me to move the while loop outside of the function itself, and allow adjust the parameters that make the loop run within the SQLQueryKafkaTesting function.

  • Related