473,394 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 1663
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ron | last post by:
have been stuck on this for several days now. I am trying to create a reverse polish calculator and I'm stuck at an intermediate stage. This is what I know I have to do (just not sure how to do it...
12
by: reynoldscraigr | last post by:
Hi All, hope someone can see what wrong here I have the following function function RemoveMenuFromHoldArray(menuName) { var i = 0; for (i=0;i<=MenusToHoldOpen.length-1;i++) { if...
0
by: GeorgeAtkins | last post by:
VS 2003 using VB.NET I'm writing a program that reads text entries from a one file and matches them against values in an XML document. However, the code seems to just sit in the loop and never get...
0
by: Mark Phillips | last post by:
Hello, I am having a problem in which a file can get stuck open when a thread that is attempting to write to it gets aborted (ThreadAbortedException occurs). The log file gets stuck open until...
1
by: Rene | last post by:
I got stuck on an infinite loop on the "Paint" event of my custom control and I was not able to "ctrl-break" my way out of it. After trying everything, I had to ctrs-alt-delete to shut down the...
5
by: Mike D | last post by:
Attached is my code. Which I know there is a better way of writing however this is what I came up with and it works until the value is null or not = to the <> value. 'Do While rdrSQL.Read() ...
7
by: steve marchant | last post by:
trying to learn VB6. Simple counting loop which counts to 8 in 1 sec intervals, then starts from 1 again and repeats. Have two Command buttons on the form. Cmd1 starts the counting, and I need to...
11
by: Tom C | last post by:
We have a window named FormApplication which just happens to be our mid parent window. When I open it in the designer, it is stuck in a loop redisplaying a c1flexgrid. maxing out our cpu's. By...
1
by: Cainnech | last post by:
Hi guys, I'm a bit stuck in an infinite loop. What I'm trying to do in the code below is to compare two arrays and if there's an item in array ALGEMEEN that is not in array ITEMS, I want to add it...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.