[Tutor] do: vs. while: (was: deleting CR within files)
Roger Merchberger
zmerch at 30below.com
Mon Apr 19 18:01:05 EDT 2004
Rumor has it that Alan Gauld may have mentioned these words:
[[[ Dudez... I'm on the list, and I hopped out of this thread quite a while
ago... ;-) ]]]
>>Is there such a thing as a do loop in Python?
>
>There's a while loop which will do anything a do loop can,
>but...
Not quite. IIRC, in VB and some other basics, there are both do/until
loops, and while/wend loops. The difference is this:
while/wend loops are always evaluated at the beginning of the loop and run
the "risk" of not get executing at all if the initial test is false; try this:
while 0:
print "You will never see this."
whereas do/until loops are evaluated at the end and always execute, at
least once, in pythonlike-parlance, it would look like this:
do:
print "you will see this anyway, even tho the test is false..."
until 0 # Yes, I know this isn't python... it's an example, eh?
As previously posted, if you *gotta have* the do/until functionality, just
use a while 1: loop, and put your test at the bottom of the loop with a
breakout, like this:
while 1:
print "You will see this once; maybe more depending on the test."
if gitmeouttahere:
break
IMNSHO, I always thought having both a do/until and while/wend loop
structures were overkill, as it was so easy to replicate one with the other...
>>done. In my program I have a simple widget and need to initiate it before
>>my dialog pops up. And then give the user the option to select more files
>>with the same widget.
>
>I think you are missing the point of event driven programming.
>When they press the widget it processes a file, if they press
>it again it processes another file, and so on.
>
>In other words you don't need a loop to do that. Or more to
>the point the Tk.mainloop() is the only loop you need.
>
>>I know that I need to use some kind of loop and in VB
>>a do loop would work best. But what about in Python?
>
>You shouldn't need a loop in VB either!
*unless* he's referencing a multi-selectable combo box - then you're both
correct. He doesn't need a loop to work the main structure of the GUI, but
he will need some form of loop to work each of the files that's been
multi-selected.
Of course, that's the beauty of "for eachfile in mycombobox:" ;-)
As an aside, in VB, the "Tk.mainloop()" structure is implied - it's totally
hidden from the user, so he may not understand why it's required in Python...
Anywho, HTH and HAND... ;-)
Roger "Merch" Merchberger
--
Roger "Merch" Merchberger --- sysadmin, Iceberg Computers
zmerch at 30below.com
Hi! I am a .signature virus. Copy me into your .signature to join in!
More information about the Tutor
mailing list