# How to loop in reverse order?(e.g. for i from 10 to 1) [closed]

I have a list F = {382.856, 638.53, 915.482, 1192.44, 1469.39, 1746.34, 2023.29, 2181.91} And I want to use it to calculate V:

I think it should be something like: V = Table[ V[i] = V[i+1] + F[i], {...loop in reverse order}], I'm not sure about the expression, and didn't find options to excute loop in reverse order.

In Mathematica's reference, I only find that Do[expr,{i,imax}] , does this mean that the loop can only go in increasing order?

-

## closed as off-topic by Michael E2, Pickett, m_goldberg, Leonid Shifrin, Simon WoodsApr 21 '14 at 14:20

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Michael E2, Pickett, m_goldberg, Leonid Shifrin, Simon Woods
If this question can be reworded to fit the rules in the help center, please edit the question.

You're not looking carefully... The same works for Table. –  Michael E2 Apr 21 '14 at 12:52

## 1 Answer

Table also supports iterating in reverse order (from the docs):

Table[expr,{i,Subscript[i, min],Subscript[i, max],di}]
uses steps di.

Table[i, {i, 10, 1, -1}]
out: {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}


What you want to do looks more like a recursive definition. For example:

f = {382.856, 638.53, 915.482, 1192.44, 1469.39, 1746.34, 2181.91}
v[8] = f[[8]];
v[i_] := v[i + 1] + f[[i]]


As a Table:

Table[v[i], {i, 8, 1, -1}]
out: {382.856, 638.53, 915.482, 1192.44, 1469.39, 1746.34, 2023.29, 2181.91}


More elegantly, your example can be expressed as FoldList:

FoldList[#1 + #2 &, 0, f]


Or in this case even:

Accumulate[f]

-
What is the difference between f[[8]] and f[8]? –  cqcn1991 Apr 21 '14 at 13:12
f[[i]] is specifically index lookup in a list/array. f[i] is applying f as a function to parameter i. –  Justin Kaeser Apr 21 '14 at 13:31