Re: how to write a C-style for loop?

2006-02-15 Thread bearophileHUGS
Steven D'Aprano>That's a completely different question, so of course it has a completely different answer. Here is one way:< Other versions without the creation of a list: for i in (2**n for n in xrange(6)): do_something(i) for i in (1

[OT] Separation of Functionality in C (was: Re: how to write a C-style for loop?)

2006-02-15 Thread Dan Sommers
On 15 Feb 2006 12:48:11 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote: > Putting the question the other way round: how would you move the > control logic out of the loop in C? I have written many functions not unlike this one (untested): void for_each_record( void (*callback)( RECORD * ), void

Re: how to write a C-style for loop?

2006-02-15 Thread John Salerno
Tim Roberts wrote: > John Salerno <[EMAIL PROTECTED]> wrote: >> I assume this is the way for loops are written in C, but if it helps to >> be specific, I'm referring to C# for loops. The Python for loop seems to >> be the same (or similar) to C#'s foreach loop: >> >> foreach int i in X >> >> But

Re: how to write a C-style for loop?

2006-02-15 Thread Duncan Booth
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

Re: how to write a C-style for loop?

2006-02-15 Thread Steven D'Aprano
On Wed, 15 Feb 2006 10:20:13 +, ZeD wrote: > Ciao, John Salerno! Che stavi dicendo? > >> for (int i = 0; i < 50; i += 5) >> >> How would that go in Python, in the simplest and most efficient way? > > i=0 > while i<50: > #... > i+=5 That's exceedingly unPythonic. In fact I'd go far

Re: how to write a C-style for loop?

2006-02-15 Thread ZeD
Ciao, John Salerno! Che stavi dicendo? > for (int i = 0; i < 50; i += 5) > > How would that go in Python, in the simplest and most efficient way? i=0 while i<50: #... i+=5 about range()/xrange(): what if you want to traslate this c-loop? for (int i=1; i<50; i*=2) -- Evangelion e' la s

Re: how to write a C-style for loop?

2006-02-15 Thread Tim Roberts
John Salerno <[EMAIL PROTECTED]> wrote: > >I assume this is the way for loops are written in C, but if it helps to >be specific, I'm referring to C# for loops. The Python for loop seems to >be the same (or similar) to C#'s foreach loop: > >foreach int i in X > >But how would you write a C# for lo

Re: how to write a C-style for loop?

2006-02-14 Thread bonono
John Salerno wrote: > for (int i = 0; i < 50; i += 5) > > How would that go in Python, in the simplest and most efficient way? for i in xrange(0,50,5): print i -- http://mail.python.org/mailman/listinfo/python-list

Re: how to write a C-style for loop?

2006-02-14 Thread Dylan Moreland
John Salerno wrote: > I assume this is the way for loops are written in C, but if it helps to > be specific, I'm referring to C# for loops. The Python for loop seems to > be the same (or similar) to C#'s foreach loop: > > foreach int i in X > > But how would you write a C# for loop in Python? Do y

how to write a C-style for loop?

2006-02-14 Thread John Salerno
I assume this is the way for loops are written in C, but if it helps to be specific, I'm referring to C# for loops. The Python for loop seems to be the same (or similar) to C#'s foreach loop: foreach int i in X But how would you write a C# for loop in Python? Do you rework a while loop, or use