Implied DO-loops provide a fast way of listing many items. These items, depending on the place where an implied DO is used, can be variables, expressions, or even implied DO-loops.
It starts with a (, followed by a set of items, separated by commas, followed by a DO variable, an equal sign, an initial value, a final value, and a step-size, end ends with a ). Like a typical DO-loop, if the step size is 1, it can be eliminated.( item-1, item-2, ...., item-n, DO-var = initial, final, step ) ( item-1, item-2, ...., item-n, DO-var = initial, final )
Depending on the place where an implied DO is used, the items can be variables, including array elements, or expressions.
The meaning of an implied DO is simple: For each possible value of the DO variable, all items (i.e., item-1, item-2, ..., item-n) are listed once and adjacent items are separated by commas.
For i=-1, the item listed is -1. For i=0, the item listed is 0. For i=1, the item listed is 1. Finally, for i=2, the item listed is 2. Combining these four cases together, the items listed by the given implied DO are( i, i = -1, 2 )
-1, 0, 1, 2
For i=1, the items listed are 1 and 1=1*1. For i=4, the items listed are 4 and 16. For i=7, the items listed are 7 and 49. Finally, for i=10, the items listed are 10 and 100. Combining these four cases together, the items listed by the given implied DO are( i, i*i, i = 1, 10, 3 )
1, 1, 4, 16, 7, 49, 10, 100
For i=1, the listed items are a(1) and b(2). For i=2, the listed items are a(2) and b(3). For i=3, the listed items are a(3) and b(4). In summary, there are six items listed as i goes from 1 to 3:( a(i), b(i+1), i = 1, 3 )
a(1), b(2), a(2), b(3), a(3), b(4)
For k=3, the listed items are 3*a(3), b(3)-c(2) and 3. For k=0, the listed items are 0*a(0), b(0)-c(-1) and 0. For k=-3, the listed items are (-3)*a(-3), b(-3)-c(-4) and -3. Therefore, there are nine listed items:( k*a(k), b(k)-c(k-1), k, k = 3, -3, -3 )
3*a(3), b(3)-c(2), 3, 0*a(0), b(0)-c(-1), 0, (-3)*a(-3), b(-3)-c(-4), -3
For i=1, the listed items are 1 and (1*j, j=1,3). For i=2, the listed items are 2 and (2*j, i=1,3). For i=3, the listed items are 3 and (3*j, j=1,3). Thus, without expanding the inner implied DO-loops, the listed items are( i, ( i*j, j = 1, 3), i = 1, 3)
Since (1*j, j=1,3) would generate 1*1, 1*2 and 1*3, (2*j, j=1,3) would generate 2*1, 2*2 and 2*3, and (3*j, j=1,3) would generate 3*1, 3*2 and 3*3, the given nested implied DO-loop generates 12 items as listed below:1, (1*j, j=1,3), 2, (2*j, j=1,3), 3, (3*j, j=1,3)
1, 1*1, 1*2, 1*3, 2, 2*1, 2*2, 2*3, 3, 3*1, 3*2, 3*3
For i=1, the listed item is (a(1)*b(j),j=1,2). For i=2, the listed item is (a(2)*b(j),j=1,2). For i=3, the listed item is (a(3)*b(j),j=1,2). Therefore, after unrolling the outer implied DO, we have:((a(i)*b(j), j=1, 2), i=1, 3)
There is no nested implied DOs in the above. Since j runs from 1 to 2, expanding these three loops yields(a(1)*b(j),j=1,2), (a(2)*b(j),j=1,2), (a(3)*b(j),j=1,2)
a(1)*b(1), a(1)*b(2), a(2)*b(1), a(2)*b(2), a(3)*b(1), a(3)*b(2)
The above is almost identical to the previous one, except that i=1,3 and j=1,2 change their positions. The result is:((a(i)*b(j), i=1, 3), j=1, 2)
This list is different from the one in the previous example.a(1)*b(1), a(2)*b(1), a(3)*b(1), a(1)*b(2), a(2)*b(2), a(3)*b(2)