Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Stuck in a loop

Reply
Thread Tools

Stuck in a loop

 
 
hexusnexus@gmail.com
Guest
Posts: n/a
 
      04-01-2008
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.
 
Reply With Quote
 
 
 
 
Dan Bishop
Guest
Posts: n/a
 
      04-01-2008
On Mar 31, 8:22 pm, (E-Mail Removed) 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.
 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      04-01-2008

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
|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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
xp re install - stuck in loop rebooting into safe mode =?Utf-8?B?SWFu?= ASP .Net 1 02-13-2007 01:20 AM
HELP! Cisco 2610 stuck in boot loop! Ivan82 Cisco 3 08-28-2006 09:20 PM
HttpModule Error Handler Stuck In Loop =?Utf-8?B?RGFuIFNpa29yc2t5?= ASP .Net 3 07-19-2006 12:14 PM
Stuck in inf loop in a multimap iterator? Steve Edwards C++ 8 03-15-2006 07:21 AM



Advertisments