Why cannot jump out the loop?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jinming Xu

    Why cannot jump out the loop?

    Hi Everyone,

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

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

    Thanks in advance!

    Jinming

    _______________ _______________ _______________ _______________ _____[color=blue]
    >From must-see cities to the best beaches, plan a getaway with the Spring[/color]
    Travel Guide! http://special.msn.com/local/springtravel.armx


  • Benoît Dejean

    #2
    Re: Why cannot jump out the loop?

    Le Thu, 29 Apr 2004 21:21:41 -0500, Jinming Xu a écrit :
    [color=blue]
    > Hi Everyone,
    >
    > I have a very simple python program, which includes a while loop. But to my
    > surprise, it cannot jump out the while loop. Does anyone know why?
    >
    > Here is the program:
    > _______________ ____________
    > #!/usr/bin/env python
    > import sys[/color]
    [color=blue]
    > n=sys.argv[1][/color]

    n = int(sys.argv[1])
    [color=blue]
    > i=0
    > while i<n:
    > print "i=",i," n=",n
    > i+=1[/color]

    ugly C style, better use range

    for i in range(int(sys.a rgv[1])):
    print i

    Comment

    Working...