while True means loop forever. The while statement takes an expression and executes the loop body while the expression evaluates to (boolean) "true". True always evaluates to boolean "true" and thus executes the loop body indefinitely. It's an idiom that you'll just get used to eventually! Most languages you're likely to encounter have equivalent idioms.
Note that most languages usually have some mechanism for breaking out of the loop early. In the case of Python it's the break statement in the cmd == 'e' case of the sample in your question.
while True means loop forever. The while statement takes an expression and executes the loop body while the expression evaluates to (boolean) "true". True always evaluates to boolean "true" and thus executes the loop body indefinitely. It's an idiom that you'll just get used to eventually! Most languages you're likely to encounter have equivalent idioms.
Note that most languages usually have some mechanism for breaking out of the loop early. In the case of Python it's the break statement in the cmd == 'e' case of the sample in your question.
my question: while WHAT is True?
While True is True.
The while loop will run as long as the conditional expression evaluates to True.
Since True always evaluates to True, the loop will run indefinitely, until something within the loop returns or breaks.
What actually "while true" statement mean can someone pull me out this?
while true statement looping in python - Stack Overflow
Can someone explain what this `while True` function is actually checking?
Is using while True loops good?
Videos
You have to modify the intb variable to something that waits for the user to input a correct value in the while statement.
You can make the first lines a function, and call it back. If it enter the else, it might do the job in your case.
You aren't changing the value of intb after you have rejected its current value. You need to repeat the call to input inside the loop.
inta=int(input("enter the first number"))
intb=input('enter + for addition, - for subtraction, * for product')
intc=int(input("enter your second number"))
while True:
if intb == '+' :
print(inta+intc)
break
if intb == '-' :
print(inta-intc)
break
if intb == '*' :
print(inta*intc)
break
else:
print("error try again")
tb=input('enter + for addition, - for subtraction, * for product')
You'll probably want separate loops for each input, to accommodate non-integer inputs for the operands. Once the values of inta, intb, and intc are confirmed valid, then you can do the requested operation.
https://pastebin.com/NWkKQc1P
It's from Automate the Boring Stuff. I tried running it through the python tutor and it didn't clarify. Is the basic point that there actually isn't anything it's checking to be True, so it's an infinite loop until you trigger the `break`?
PS I figure this is something simple from much earlier that I didn't internalize. I plan to go through all the basic curriculum again to make sure there aren't any gaps in super basic knowledge.