What the spec says on the subject:
Iteration loops have the form:
IM IN YR <label> <operation> YR <variable> [TIL|WILE <expression>]
<code block>
IM OUTTA YR <label>
Where <operation> may be UPPIN (increment by one), NERFIN (decrement by one), or any unary function. That operation/function is applied to the <variable>, which is temporary, and local to the loop. The TIL <expression> evaluates the expression as a TROOF: if it evaluates as FAIL, the loop continues once more, if not, then loop execution stops, and continues after the matching IM OUTTA YR <label>. The WILE <expression> is the converse: if the expression is WIN, execution continues, otherwise the loop exits.
Question
My gripe with the spec is the combination of:
- the lack of a loop variable initializer
- the fact it's temporary and local to the loop
As I understand it, this means it has to start at 0.
While that's mostly ok for most uses of UPPIN, it's totally off for most (my) intended uses of NERFIN. My most common uses of a decrementing loop variable in other languages are the "repeat n times (n not re-used)" idiom and string operations, which wouldn't be a good idea in LOLCODE anyway.
Is it possible to use NERFIN to get a loop decrement from n to 1 or 0 in a way that's less verbose than the equivalents with UPPIN or the operationless forms of looping?
Alternatives' comparison
Printing 5 4 3 2 1 with the UPPIN variant:
IM IN YR LOOPZ UPPIN YR COWNTR TIL BOTH SAEM COWNTR AN 5
VISIBLE DIFF OF 5 AN COWNTR
IM OUTTA YR LOOPZ
Pros: concise.
Cons: actual loop variable is not accessible directly.
With the operationless variant:
I HAS A COWNTR ITZ 5
IM IN YR LOOPZ
VISIBLE COWNTR
COWNTR R DIFF OF COWNTR AN 1
BOTH SAEM COWNTR AN 0, O RLY?
YA RLY, GTFO, OIC
IM OUTTA YR LOOPZ
Pros: loop variable is directly available.
Cons: longer.
Best I can get with NERFIN:
IM IN YR LOOPZ NERFIN YR COWNTR TIL BOTH SAEM COWNTR AN -5
VISIBLE SUM OF 5 AN COWNTR
IM OUTTA YR LOOPZ
Pros: err... uses NERFIN?
Cons: loop variable isn't directly accessible; less readable (hah!) than the UPPIN variant; no gain in verbosity.
TLDR question, repeated
Is it possible to use NERFIN to get a loop decrement from n to 1 or 0 in a way that's less verbose than the equivalents with UPPIN or the operationless forms of looping?
I'm using the lci interpreter at language specification level 1.2.