Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 while Loop Help
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mms6




PostPosted: Fri Oct 23, 2009 10:30 pm   Post subject: while Loop Help

[copy-pasta of an assignment that's not really relevant]

code:
result = 0

while i <= hi:
        lo += 1
        hi += 1
        result = lo + hi



I get infinite loop

Help anyone?
Thanks
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Oct 23, 2009 10:52 pm   Post subject: Re: while Loop Help

mms6 @ Fri Oct 23, 2009 10:30 pm wrote:

code:

while i <= hi:


When is i > hi ?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
andrew.




PostPosted: Sat Oct 24, 2009 7:28 am   Post subject: RE:while Loop Help

What are the initial values of i and hi? i is probably always less than hi because hi is increasing, and therefore the loop will never end.
Vish




PostPosted: Sat Jul 16, 2011 9:14 am   Post subject: Re: while Loop Help

you have not set a variable called i, so therefore, you should get nothing.

the loop doesn't brake until the condition is broken, so, if you want the loop to die, break it.
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: