I can do a control loop like this in C++

int case =0;
 while( case<0 && case>20){}

How am i suppose to implement this in Python? I didn't get any errors if i wrote this, the problem is it doesn't enter the while loop when case<0 and case>5

while case<0 & case>5:

Hi!

So you want to do something if case is smaller than 0 or greater than 20, right?

while case<0 or case>20: do something

If case should be between 0 and 20:

while 0<case<20: do something

Hope this helps.

Regards, mawe

If case <=2 or case >=5, it will enter the while loop. the code below doesn't solve my problem. why can't it enter the while loop when my case match this condition case <=2 or case >=5

while case<0 or case>20: do something

Something like this works fine:

try:
    case = int(raw_input("enter a number less then 3 or more than 4: "))
except:
    case = 0
while case <=2 or case >=5:
    # do something to get out of loop
    case += 1
    print case
    if case > 10: break

Notice that case is reserved keyword in C++, also notice that && is and || is or in Python. A simple & is bitwise and in C++ and Python.

This question has already been answered. Start a new discussion instead.