Skip to content

FIX: Retain parent FOR loop's $idx variable in IF command content#423

Open
deedw wants to merge 1 commit into
guigrpa:masterfrom
deedw:if-command-retain-$idx
Open

FIX: Retain parent FOR loop's $idx variable in IF command content#423
deedw wants to merge 1 commit into
guigrpa:masterfrom
deedw:if-command-retain-$idx

Conversation

@deedw

@deedw deedw commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

As described in the README, the IF command is implemented using a FOR loop with 1 or 0 iterations.

A side-effect of this is that the $idx variable is also reset to 0 within the IF command content. For example:

+++FOR value IN ['a', 'b', 'c'] +++
+++INS $idx +++
+++IF value==='c' +++
+++INS $idx +++
+++END-IF +++
+++END-FOR value +++

will generate:

0
1
2
0

when expected output would be:

0
1
2
2

This pull request changes the behaviour so that the output is as expected and the innermost FOR loop $idx value is retained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant