By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,404 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,404 IT Pros & Developers. It's quick & easy.

Limiting output for loop

P: 1
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:

Expand|Select|Wrap|Line Numbers
  1. start = form["start"].value
  2. end = form["end"].value
  3. .
  4. .
  5. for char in range(int(start),int(end)+1):
  6.     name = unicodedata.name(unichr(char), "undefined" )
  7.     if name != "undefined":
  8.         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:
Expand|Select|Wrap|Line Numbers
  1. for count, char in enumerate(range(int(start),int(end)+1)):
  2.   if count >= 200:
  3.       break
But nothing seems to work.

Thank you in advance for any help.
Nov 14 '08 #1
Share this Question
Share on Google+
2 Replies


Curtis Rutland
Expert 2.5K+
P: 3,256
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
Nov 14 '08 #2

bvdet
Expert Mod 2.5K+
P: 2,851
I think you were on the right track. You were trying to do something like this:
Expand|Select|Wrap|Line Numbers
  1. >>> for i, count in enumerate(range(100,120)):
  2. ...     if i > 10:
  3. ...         break
  4. ...     print count
  5. ...     
  6. 100
  7. 101
  8. 102
  9. 103
  10. 104
  11. 105
  12. 106
  13. 107
  14. 108
  15. 109
  16. 110
  17. >>> 
Nov 14 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.