Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Why cannot jump out the loop?

Reply
Thread Tools

Re: Why cannot jump out the loop?

 
 
Skip Montanaro
Guest
Posts: n/a
 
      04-30-2004

Jinming> I have a very simple python program, which includes a while
Jinming> loop. But to my surprise, it cannot jump out the while
Jinming> loop. Does anyone know why?

Jinming> Here is the program:
Jinming> ___________________________
Jinming> #!/usr/bin/env python
Jinming> import sys
Jinming> n=sys.argv[1]
Jinming> i=0
Jinming> while i<n:
Jinming> print "i=",i," n=",n
Jinming> i+=1
Jinming> -----------------------------------------------------

You need to convert sys.argv[1] to an integer. Try this instead:

#!/usr/bin/env python
import sys
n = int(sys.argv[1])
i = 0
while i < n:
print "i=", i, " n=", n
i += 1

Comparisons between any two objects generally always succeed (this
facilitates sorting of heterogenous lists), but doesn't always sort in
useful ways:

>>> "1" > 1000

True

Skip

 
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
Cannot jump to new part of Silverlight video when using handler Roger Martin ASP .Net 17 12-18-2008 02:00 AM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Double left click jump to top, same with ctrl or shift to jump to bottom? Eadwine Rose Javascript 2 10-15-2006 08:38 PM
Why cannot jump out the loop? Jinming Xu Python 1 04-30-2004 06:02 AM



Advertisments