dbjohn
dbjohn

Reputation: 1005

Basic Python While loop compound conditional evaluation

In Python IDLE Shell it seems I cannot use a compound conditional expression and a while loop. I tried it within brackets too. Take these two examples:

k=0
m=0
while k<10 & m<10:
    print k
    k +=1
    m+=1

This doesn't evaluate the second condition. But if I write

 while k<10:
    print k
    k+=1

This does work. Is there a way I could achieve the first block of code with the "and" operator. I have done it in Java. Do I just need to put together "if" statements to achieve the same functionality in Python?

Upvotes: 0

Views: 2005

Answers (1)

Deniz Dogan
Deniz Dogan

Reputation: 26227

& should be and. & is the bitwise AND operator.

Upvotes: 7

Related Questions