Limiting output for loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rx25c
    New Member
    • Nov 2008
    • 1

    Limiting output for loop

    Hi.

    I'm trying to limit the output of a for loop to 200 counts and then breaking it. The purpose of the loop is to print out defined unicode characters onto a html table after a user sets the range.

    So far I have this:

    Code:
    start = form["start"].value
    end = form["end"].value
    .
    .
    for char in range(int(start),int(end)+1):
        name = unicodedata.name(unichr(char), "undefined" )
        if name != "undefined":
            print "<tr><td class=\"num\">" + str(char) + "</td><td><code class=\"html\">&amp;#" + str(char) + ";</code>""</td><td class=\"char\"><span>&#" + str(char) + ";</span></td><td class=\"name\">" + name + "</td></tr>"
    I've tried using this within the loop:
    Code:
    for count, char in enumerate(range(int(start),int(end)+1)):
      if count >= 200:
          break
    But nothing seems to work.

    Thank you in advance for any help.
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Please enclose your posted code in [CODE] [/CODE] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use [CODE] [/CODE] tags in future.

    MODERATOR

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      I think you were on the right track. You were trying to do something like this:
      [code=Python]>>> for i, count in enumerate(range (100,120)):
      ... if i > 10:
      ... break
      ... print count
      ...
      100
      101
      102
      103
      104
      105
      106
      107
      108
      109
      110
      >>> [/code]

      Comment

      Working...