Re: how to write a C-style for loop?
- From: Duncan Booth <duncan.booth@xxxxxxxxxxxxxxx>
- Date: 15 Feb 2006 12:48:11 GMT
Steven D'Aprano wrote:
about range()/xrange(): what if you want to traslate this c-loop? for
(int i=1; i<50; i*=2)
That's a completely different question, so of course it has a completely
different answer. Here is one way:
.... various options snipped ...
and another way for use when you have more than one loop following this
pattern:
def powerrange(base, start=0, limit=0):
value = base**start
while value < limit:
yield value
value *= base
for i in powerrange(2,0,50):
dosomething(i)
Putting the question the other way round: how would you move the control
logic out of the loop in C?
.
- Follow-Ups:
- References:
- how to write a C-style for loop?
- From: John Salerno
- Re: how to write a C-style for loop?
- From: ZeD
- Re: how to write a C-style for loop?
- From: Steven D'Aprano
- how to write a C-style for loop?
- Prev by Date: Re: Rethinking the Python tutorial
- Next by Date: Re: pop line from file
- Previous by thread: Re: how to write a C-style for loop?
- Next by thread: [OT] Separation of Functionality in C (was: Re: how to write a C-style for loop?)
- Index(es):
Relevant Pages
|