0

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!

MM PP
  • 4,050
  • 9
  • 35
  • 61

3 Answers3

2

It means the loop is counting downwards (-1) starting at k1, finishing at 1.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
2

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
Amadan
  • 191,408
  • 23
  • 240
  • 301
1

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--)
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547