python for loop

Lada Kugis lada.kugis at gmail.com
Wed Apr 1 04:13:18 CEST 2009


On Tue, 31 Mar 2009 21:13:05 -0400 (CLT), "andrew cooke"
<andrew at acooke.org> wrote:

>Lada Kugis wrote:
>> I'm coming from fortran and
>   *********** c ***********
>> background so I'm certainly biased by
>> them. But if you could explain one thing to me:
>
>but this is exactly the same behaviour as the standard way of doing things
>in c!
>
>int a[5];
>for (i = 0; i < 5; ++i) {
>  a[i] = 0;
>}
>
>were you being honest about the c background?!
>

:-)
Yes, I usually avoid lyes. They are hard to remember.

In C you can do it either way, I usually use the one starting from 1
and with "=", since that way it corresponds to my paper data.
Why it troubles me so much: for example, I'm doing the FEM analysis of
a simple ... uhmm, not sure how you say this, stick or beam or girder

node 1 ******* node 2 ******* node 3

I have n=3 nodes and n-1 elements. The matrix will have 3 rank.
The indexes in the matrix correspond to the nodes, and so on.
(this is just an elementary example, but you probably understand)

If I try this in py, it goes for i in range(0,3) then it gets all
moved by one. If I go (1,4) then it ...

Lada



>andrew
>




More information about the Python-list mailing list