User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 456,555 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,473 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 1361 | Replies: 5 | Solved
Reply
Join Date: Oct 2007
Posts: 30
Reputation: jliu66 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jliu66 jliu66 is offline Offline
Light Poster

a block of python codes in a loop

  #1  
Oct 18th, 2007
Hi, My friends,

I am new to python. I try to figure out how python knows the end of loop or the end of a block of codes in while... else code
Here is the example:
while E:
Bt
else:
Bf


here if Bf have 20 lines of code. How the python knows which line of code is the end of else:

It looks like I miss something, which is quite different from all other languages.

Thanks in advance.

John
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 24
Reputation: jice is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
jice jice is offline Offline
Newbie Poster

Re: a block of python codes in a loop

  #2  
Oct 19th, 2007
Hi,
In python, blocks structure rely on indentation
while E:
    Bt
else:
    Bf
back to the while level
Reply With Quote  
Join Date: Oct 2007
Posts: 30
Reputation: jliu66 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
jliu66 jliu66 is offline Offline
Light Poster

Re: a block of python codes in a loop

  #3  
Oct 19th, 2007
Originally Posted by jice View Post
Hi,
In python, blocks structure rely on indentation
while E:
    Bt
else:
    Bf
back to the while level



Thanks a lot. But this is kind of risky for a large project as you may have many loop and if to have indentations.

John
Reply With Quote  
Join Date: Oct 2007
Posts: 24
Reputation: jice is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
jice jice is offline Offline
Newbie Poster

Re: a block of python codes in a loop

  #4  
Oct 19th, 2007
Well, maybe... I don't think this may be a problem. it's just like when you have to be careful about {{{ and }}}.
The positive point of that is that you HAVE to be careful of your code readability.
Python is compact and clear (and that's why I use it instead of perl for instance)
Reply With Quote  
Join Date: Sep 2007
Posts: 19
Reputation: paddy3118 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
paddy3118 paddy3118 is offline Offline
Newbie Poster

Tutorial Re: a block of python codes in a loop

  #5  
Oct 20th, 2007
Originally Posted by jliu66 View Post
Thanks a lot. But this is kind of risky for a large project as you may have many loop and if to have indentations.

John


Not really. For your large project you factor and re-factor the code, to improve maintainability which also improves readability.

People have add-hoc rules like "a function should fit on a screen", or "excessive textual nesting of loops and conditionals is bad"; they are good for any language. It usually means looking at a large function and finding out why it is large with a view to encapsulating some of its functionality in another function that will be called instead.

- Paddy.
Reply With Quote  
Join Date: Mar 2007
Posts: 1,449
Reputation: Lardmeister is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 8
Lardmeister's Avatar
Lardmeister Lardmeister is offline Offline
Nearly a Posting Virtuoso

Re: a block of python codes in a loop

  #6  
Oct 20th, 2007
I understand that most editors written for Python will make you aware of indentation problems, since they are so important for this language.
I upped my sanitary measures, up yours!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Python Forum

All times are GMT -4. The time now is 5:31 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC