Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 29th, 2007, 7:46 PM   #1
mark
Newbie
 
Join Date: Mar 2006
Posts: 14
Rep Power: 0 mark is on a distinguished road
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.
mark is offline   Reply With Quote
Old Apr 29th, 2007, 7:47 PM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 841
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
No. In Python, code blocks are defined by their indentation.

Last edited by titaniumdecoy; Apr 29th, 2007 at 7:58 PM.
titaniumdecoy is offline   Reply With Quote
Old May 1st, 2007, 1:11 PM   #3
Fred
Programmer
 
Fred's Avatar
 
Join Date: Feb 2005
Posts: 67
Rep Power: 4 Fred is on a distinguished road
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!
Fred is offline   Reply With Quote
Old May 1st, 2007, 2:30 PM   #4
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
If your statement block is short, you can do it all on one line:
for x in range(1, 11): x *=3; print x
Honestly, the indented way is much more readable!

Hi Fred!
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old May 1st, 2007, 5:25 PM   #5
ptmcg
Newbie
 
Join Date: Aug 2005
Location: Austin, TX
Posts: 15
Rep Power: 0 ptmcg is on a distinguished road
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 ]
ptmcg is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:44 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC