471,082 Members | 915 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,082 software developers and data experts.

Stuck in a loop

I wrote a simple algorithm and it keeps getting stuck in a loop. I
guess I'm just to tired to figure it out:

compcount=[5,4,2,2]
suitrank=[0,0,0,0]

trump=2
l,lt=0,0
while l<4:
while lt<4:
if l==trump:
l+=1
if l>3:
break
if lt==trump:
lt+=1
if compcount[l]<compcount[lt]:
suitrank[l]+=1
lt+=1
l+=1

In case you're wondering, the point is to rank suits from highest to
lowest based on how few cards each suit has. I hope that's enough
information.
Apr 1 '08 #1
2 1546
On Mar 31, 8:22 pm, hexusne...@gmail.com wrote:
I wrote a simple algorithm and it keeps getting stuck in a loop. I
guess I'm just to tired to figure it out:

compcount=[5,4,2,2]
suitrank=[0,0,0,0]

trump=2
l,lt=0,0
while l<4:
while lt<4:
if l==trump:
l+=1
if l>3:
break
if lt==trump:
lt+=1
if compcount[l]<compcount[lt]:
suitrank[l]+=1
lt+=1
l+=1

In case you're wondering, the point is to rank suits from highest to
lowest based on how few cards each suit has. I hope that's enough
information.
Inside the inner loop, lt never changes if lt != trump, so you get an
infinite loop the first time when lt == 0.

I think you may have misindented the last two lines.
Apr 1 '08 #2

<he********@gmail.comwrote in message
news:e1**********************************@c26g2000 prf.googlegroups.com...
|I wrote a simple algorithm and it keeps getting stuck in a loop. I
| guess I'm just to tired to figure it out:

The easiest way to figure out somethinglike this is to print your variables
from inside the loop to see things stick, or if there is a cycle.

| compcount=[5,4,2,2]
| suitrank=[0,0,0,0]
|
| trump=2
| l,lt=0,0
| while l<4:
| while lt<4:

print l, lt

| if l==trump:
| l+=1
| if l>3:
| break
| if lt==trump:
| lt+=1
| if compcount[l]<compcount[lt]:
| suitrank[l]+=1
| lt+=1
| l+=1

Apr 1 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by reynoldscraigr | last post: by
reply views Thread by GeorgeAtkins | last post: by
reply views Thread by Mark Phillips | last post: by
1 post views Thread by Rene | last post: by
5 posts views Thread by Mike D | last post: by
7 posts views Thread by steve marchant | last post: by
11 posts views Thread by Tom C | last post: by
1 post views Thread by Cainnech | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.