0

So I'm trying to run a while loop, which should ideally stop when winner is either True or False. The table.isWinner() method returns either one of these values. But the loop for some reason is not getting stopped, until outerCount is bigger than tableColNum*tableRowNum (the other condition).

            tableRowNum = table.getNumRows()
            tableColNum = table.getNumColumns()
            stackNum = table.getNumStacks()
            winner = None
            outerCount = 0
            while winner == None and outerCount < tableColNum*tableRowNum:
                for i in range(tableRowNum):
                    for j in range(tableColNum):
                        domino = table.select(i, j)
                        played = None
                        count = 0
                        while count < stackNum and not played:
                            played = table.playDomino(domino, count)
                            count += 1
                        print(table)
                        winner = table.isWinner()
                        print(winner)
                        outerCount += 1
Sukanta
  • 75
  • 6
  • 2
    The *outer* loop condition won't be checked again until *after* all the inner loops also end (or break). – user2864740 Mar 23 '21 at 22:42
  • 1
    FYI you should use `is None` rather than `== None`: https://stackoverflow.com/questions/14247373/python-none-comparison-should-i-use-is-or – Random Davis Mar 23 '21 at 22:43
  • Also, [this question](https://stackoverflow.com/questions/189645/how-to-break-out-of-multiple-loops) is quite relevant to your issue and goes into how you can solve it. – Random Davis Mar 23 '21 at 22:45
  • It seems like you intend the inner for loops to stop *immediately*, *as soon as* the `winner` value gets set to something other than `None`. Yes? Loops don't work that way. The loop condition is only checked at the top of the loop, not continuously. – Karl Knechtel Mar 23 '21 at 22:45
  • By the inner loops, do you mean the for loops? Because the inner `while` loop does end when `.iswinner()` is evaluated and set to `winner`. – Sukanta Mar 23 '21 at 22:46
  • OHHH I see. Dear lord I had this basic understanding wrong. Thank you so much! – Sukanta Mar 23 '21 at 22:47

0 Answers0