![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Mar 2006
Posts: 14
Rep Power: 0
![]() |
loops
hello im trying to figure out how to specify which code is part of the loop and which is not, on the tutorial im reading it says to indent the code, but is there any other better way to do it.
|
|
|
|
|
|
#2 |
|
Expert Programmer
|
No. In Python, code blocks are defined by their indentation.
Last edited by titaniumdecoy; Apr 29th, 2007 at 7:58 PM. |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Feb 2005
Posts: 67
Rep Power: 4
![]() |
As far as I know it is the only way...
That's just python. There is no 'end of loop' statement! U' get used to it! |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
If your statement block is short, you can do it all on one line:
for x in range(1, 11): x *=3; print x Hi Fred!
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Aug 2005
Location: Austin, TX
Posts: 15
Rep Power: 0
![]() |
If you are looping for the purpose of building a list, read up on list comprehensions. Here is a quick way to build a list of the odd numbers up to 20:
print [c for c in range(20) if c%2 ] |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| For Loops in this Code | SonicReducer | C++ | 5 | Apr 10th, 2007 3:36 AM |
| Loops in Python | Dietrich | Python | 4 | Jan 6th, 2007 11:34 AM |
| Multiple Loops | HackeZ | C++ | 27 | Dec 25th, 2005 12:19 PM |
| For Loops | splitterdevildoll | C++ | 9 | Aug 24th, 2005 8:24 PM |
| nested loops in vb | edspeth | Visual Basic | 2 | Mar 25th, 2005 10:27 AM |