Jensen's Device: Difference between revisions
→{{header|Forth}}
(→{{header|Forth}}: added macro-based variant) |
|||
Line 756:
This splits <code>sum</code> in two macros: <code>sum<</code> and <code>>sum</code>; in <code>main</code> these two words surround the code corresponding to <code>1/i</code> in the Algol 60 version. The loop limits are <code>101 1</code>, passed on the stack to <code>sum<</code> in the order and semantics (upper bound is excluded) idiomatic in Forth.
Concerning the <code>i</code> parameter of the Algol 60 version, that is an artifact of the role of variables for storing data and passing it around in Algol-family languages. Forth's counted loops can access the current loop counter of the innermost loop with <code>i</code> (which is not a variable) without setting a variable, and that is also what one uses inside <code>sum<</code> ... <code>>sum</code>, as shown in <code>main</code>.
=={{header|Fortran}}==
|