I have a code in pseudocode.
This is a line of code: for i=k1,1,-1 do Ti <- Ti-1 + Ti
.
k1
is an integer. Ti
is an array.
The question is: what means for i=k1,1,-1
? I know what is for
but I don't know what is i=k1,1,-1
.
Thank you!
I have a code in pseudocode.
This is a line of code: for i=k1,1,-1 do Ti <- Ti-1 + Ti
.
k1
is an integer. Ti
is an array.
The question is: what means for i=k1,1,-1
? I know what is for
but I don't know what is i=k1,1,-1
.
Thank you!
It means the loop is counting downwards (-1) starting at k1, finishing at 1.
Have i
assume values from k1
to 1
with steps of -1
. Equivalent to C:
for (i = k1; i >= 1; i += -1)
The syntax in your question is basically same as in Fortran, been around for decades:
DO 10,i=k1,1,-1
T(i) = T(i-1) + T(i)
10 CONTINUE
It probably means that i
starts at k1
and decreases to 1
by steps of -1
, i.e. in C
for (i=k1; i>=1; i--)