[EMAIL PROTECTED] wrote:
> The range() function a nice one to create a list and enumerate it with a
> 'foreach'.
> But it creates a static list and enumerates it.
> The spice of 'for' of perl, java, C and ... is that you haven't know the
> list before you enumerate it.
Which creates all sorts of opportunities to misjudge what you're actually
looping on.
> It is frustrate me when i tried :
>
> while b = func(a):
> print something....
>
> assignment isn't posseible in while.
Assignment is not possible in any expression. This is because one of the
most common bugs in C/C++ (and other languages that allow this), is to
accidentally use assignment when you intended comparison. Indeed, many/most
C compilers will issue a warning when you use assignment in a conditional
expression.
It really isn't that much worse to use
while 1:
b = func(a)
if not b:
break
Yes, it's a bit longer, but it's also very clear that the assignment was
intentional, and wasn't supposed to be a comparison. Explicit is better
than implicit.
> In Perl, or in C i can write
>
> for(a=12, b=a+1, c=&p, d=&a, d=func(kjlkjl), ... ; comp(d, a); a++, b++,
> c++, d++) {
>
> }
Which does what?? Ugh, what a mess. Never mind the fact that you're
binding the same variable twice during the initialization (and which one
will get priority??).
a, c, d = 12, p, func(kjl)
while 1:
if not comp(d, a):
break
b = a + 1
DoSomeProcessing(a, b, c, d)
a += 1
b += 1
d += 1
This might take a few more lines, but at least you can *see* what is
happening. And it's not like vertical space is a rare and precious
resource... ;)
> I know it is a different language, but how can i do it in python?
> How i have to thinking ?
Python was designed with the thought that the average programmer spends
*far* more time *reading* code than writing code. So the intent of Python
syntax is to make code that is easy to *read*, even if it takes a little bit
more effort to write. That extra effort will pay off the first time that
you have to change something that you wrote more than a week ago. Or have
to work with someone *else's* code. Python code is *much* easier to
maintain than C or Perl.
Jeff Shannon
Technician/Programmer
Credit International
_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython