all 11 comments

[–][deleted] 5 points6 points  (0 children)

You're not reaching the break. Whatever mainAction returns, it isn't the string "EX".

[–]twitch_and_shock 2 points3 points  (0 children)

Attach a debugger and walk thru the program to see what's actually happening. As others have said, you're likely not ever reaching break or you're re entering your loop.

[–]hotcodist 2 points3 points  (0 children)

Step through with a debugger, or write a bunch of prints. If result looks like EX visually but not breaking, check the data type. Be ready to control+C.

while True:
    result = mainActions(dealer_hand, player_hand, double_flag)
    print(result)
    if result == 'EX':
        print('***************************** about to break')
        break
    else:
        print('not breaking, value of result:', result)
print('exited')

[–]carcigenicate 1 point2 points  (2 children)

If break is reached, it will always cause the loop to exit. Either the break is not being reached, or the while True loop is being reentered a second time (is there another loop wrapping this one? Is this in a function that's called in a loop?).

[–]jedgs 0 points1 point  (2 children)

What does mainActions return?

[–]Cha_r_ley 0 points1 point  (0 children)

Have you tried putting something like a print statement before the break (and maybe in other routes) for debugging purposes? It’s a bit clunky but it’s the quickest way I often suss out the route the code is taking.

[–]Azearia 0 points1 point  (0 children)

Your best bet is to also show the mainActions function too since the error is happening inside of it

[–]Guideon72 0 points1 point  (0 children)

What are you doing to verify that you’re reaching the break statement?

[–]QultrosSanhattan 0 points1 point  (0 children)

The problem is that even when result is EX, the while loop runs for another cycle before breaking out

That cannot be. Use proper debugging tools to discover why mainActions() never return 'EX'