This is a small code snippet which is causing my program to crash due to an infinite loop
while not stack.is_empty():
if operators[stack.peek()] >= operators[character]:
result += stack.pop()
where stack is a Stack object and operators is a dictionary. The below code however does not cause an infinite loop
while not stack.is_empty() and operators[stack.peek()] >= operators[character]:
result += stack.pop()
My question is: Aren't these code snippets basically the same thing ? Why is one causing an infinite loop while the other isn't?
Thanks