1

If I wanted to say something for a while loop such as: while time is greater than or equal to 0, would it simply be written as while time > or == 0? Or is there no way to do this?

asked Dec 15, 2013 at 5:51
2
  • 1
    docs.python.org/3/reference/expressions.html#not-in Commented Dec 15, 2013 at 5:53
  • The relation "is greater than or equal to" is treated as a single statement, not an alternation of two disjoint ones. The presence of the word "or" in the English reading doesn't imply that the operator or is involved in the translation to Python. In mathematics, this "greater than or equal" relationship is written with the symbol ≥, but usually in programming languages, and certainly in Python, it's written >=. Commented Dec 15, 2013 at 5:58

3 Answers 3

6

Use while time >= 0 (equivalent to while time > 0 or time == 0)

>>> 0 >= 0
True
>>> 1 >= 0
True
>>> -1 >= 0
False
answered Dec 15, 2013 at 5:53
Sign up to request clarification or add additional context in comments.

Comments

0

It would be:

while time >= 0:
 pass
 #here be dragons
answered Dec 15, 2013 at 5:52

Comments

0

Counting in Python example:

time = 0 
while time < 100: 
 time = time + 1 
 print time
answered Dec 15, 2013 at 6:00

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.