Search code examples
pseudocode

What means for i=a,1,-1 in pseudocode?


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!


Solution

  • 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