Re: do/while structure needed
Dennis Lee Bieber wrote: > Would you put the condition at the top of the loop -- and confuse > those people who believe the exit condition should appear at the point > the exit activates? Confusion is not the issue. You can put the condition smack dab in the middle of the loop, as long as the location is consistent people will know where to look for it. Rejecting because "some are confused the first time since other languages do it differently" gets you nowhere: some group will always be confused by something. They learn, problem solved. I agree that do/while is unnecessary. But I'd argue against it on grounds of simplicity and readability instead of confusion. -- Edward Elliott UC Berkeley School of Law (Boalt Hall) complangpython at eddeye dot net -- http://mail.python.org/mailman/listinfo/python-list
Re: do/while structure needed
Dennis Lee Bieber wrote: > And what syntax would you propose? I guess something like: do: stuff goes here and here and here while (condition) The absence of a colon after the while statement can be the signal that it isn't a regular while statement with a following block, but instead the final statement of a do/while loop. Or would that cause an issue? -- http://mail.python.org/mailman/listinfo/python-list
Re: do/while structure needed
Op 2006-05-15, Terry Reedy schreef <[EMAIL PROTECTED]>: > > "John Salerno" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> Thanks, that looks pretty good. Although I have to say, a do/while >> structure is the much more obvious way. I wonder why it hasn't been >> added to the language. > > Been suggested many times, been considered, and rejected. Easily similated > with while True: ... if exit_condition: break which also solves 'loop and a > half' problem, which is more common. Requires new keyword for little gain. > Etc. It isn't rejected. PEP 315 is only deferred. Which as far as I understand means it is postponed because other things seemed more important. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: do/while structure needed
Terry Reedy wrote: > "John Salerno" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> Thanks, that looks pretty good. Although I have to say, a do/while >> structure is the much more obvious way. I wonder why it hasn't been >> added to the language. > > Been suggested many times, been considered, and rejected. Easily similated > with while True: ... if exit_condition: break which also solves 'loop and a > half' problem, which is more common. Requires new keyword for little gain. > Etc. I know, I remember a discussion about it a while back. But IMO, at least, a do/while structure seems much cleaner and more readable than a while loop with an embedded if and break statement. -- http://mail.python.org/mailman/listinfo/python-list
Re: do/while structure needed
"John Salerno" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Thanks, that looks pretty good. Although I have to say, a do/while > structure is the much more obvious way. I wonder why it hasn't been > added to the language. Been suggested many times, been considered, and rejected. Easily similated with while True: ... if exit_condition: break which also solves 'loop and a half' problem, which is more common. Requires new keyword for little gain. Etc. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: do/while structure needed
George Sakkis wrote: > while True: > random.shuffle(letters) > trans_letters = ''.join(letters)[:len(original_set)] > if some_compatison(original_set,trans_letters): > trans_table = string.maketrans(original_set, trans_letters) > break Thanks, that looks pretty good. Although I have to say, a do/while structure is the much more obvious way. I wonder why it hasn't been added to the language. -- http://mail.python.org/mailman/listinfo/python-list
Re: do/while structure needed
"Ten" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Sunday 14 May 2006 06:17, John Salerno wrote: > > 1 random.shuffle(letters) > > 2 trans_letters = ''.join(letters)[:len(original_set)] > > 3 trans_table = string.maketrans(original_set, trans_letters) > > > > So what I'd like to do is have lines 1 and 2 run once, then I want to do > > some comparison between original_set and trans_letters before running > > line 3. If the comparison passes, line 3 runs; otherwise, lines 1 and 2 > > run again. > > > > A do/while would be good for this, but perhaps I'm looking at it in the > > wrong way? Or is there some kind of do/while type of idiom that I could > > use? > > > > Thanks. > > while not comparison(original_set, trans_letters): > random.shuffle(letters) > trans_letters = ''.join(letters)[:len(original_set)] > > trans_table = string.maketrans(original_set, trans_letters) > I don't think the OP wants to call comparison until after the first pass through the loop. Here's a modification to your version that skips the comparison test on the first pass: first = True while first or not comparison(original_set, trans_letters): first = False random.shuffle(letters) trans_letters = ''.join(letters)[:len(original_set)] trans_table = string.maketrans(original_set, trans_letters) -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: do/while structure needed
On Sunday 14 May 2006 06:17, John Salerno wrote: > 1 random.shuffle(letters) > 2 trans_letters = ''.join(letters)[:len(original_set)] > 3 trans_table = string.maketrans(original_set, trans_letters) > > So what I'd like to do is have lines 1 and 2 run once, then I want to do > some comparison between original_set and trans_letters before running > line 3. If the comparison passes, line 3 runs; otherwise, lines 1 and 2 > run again. > > A do/while would be good for this, but perhaps I'm looking at it in the > wrong way? Or is there some kind of do/while type of idiom that I could > use? > > Thanks. while not comparison(original_set, trans_letters): random.shuffle(letters) trans_letters = ''.join(letters)[:len(original_set)] trans_table = string.maketrans(original_set, trans_letters) HTH, Ten -- There are 10 types of people in this world, those who understand binary, and those who don't. -- http://mail.python.org/mailman/listinfo/python-list
Re: do/while structure needed
John Salerno wrote: > 1 random.shuffle(letters) > 2 trans_letters = ''.join(letters)[:len(original_set)] > 3 trans_table = string.maketrans(original_set, trans_letters) > > So what I'd like to do is have lines 1 and 2 run once, then I want to do > some comparison between original_set and trans_letters before running > line 3. If the comparison passes, line 3 runs; otherwise, lines 1 and 2 > run again. > > A do/while would be good for this, but perhaps I'm looking at it in the > wrong way? Or is there some kind of do/while type of idiom that I could use? > > Thanks. I guess you want something like: while True: random.shuffle(letters) trans_letters = ''.join(letters)[:len(original_set)] if some_compatison(original_set,trans_letters): trans_table = string.maketrans(original_set, trans_letters) break HTH, George -- http://mail.python.org/mailman/listinfo/python-list
do/while structure needed
1 random.shuffle(letters) 2 trans_letters = ''.join(letters)[:len(original_set)] 3 trans_table = string.maketrans(original_set, trans_letters) So what I'd like to do is have lines 1 and 2 run once, then I want to do some comparison between original_set and trans_letters before running line 3. If the comparison passes, line 3 runs; otherwise, lines 1 and 2 run again. A do/while would be good for this, but perhaps I'm looking at it in the wrong way? Or is there some kind of do/while type of idiom that I could use? Thanks. -- http://mail.python.org/mailman/listinfo/python-list