When asking a question you need to state the name and version of the Story Format you are using, as answers can be different for each one. I will assume you are using v2.0.0 because the 1.x series does not have a (for:) macro.
Harlowe 2.x's implementation of a for loop is designed to iterate through a collection, and I could not find anything in it's documentation to indicate that you could stop that iteration.
You can however use a variable to control if anything is done during that each loop, as the following demonstrates.
[]<output|
(set: $list to (array: "one", "two", "three", "four", "five"))
(set: $continue to true)
(for: each _item, ...$list)[
<!-- your condition check goes here. -->
(if: _item is "three")[
(set: $continue to false)
]
(if: $continue)[
<!-- the code applied on each iteration goes here. -->
(append: ?output)[<br>_item]
]
]
warning: For reasons unknown, changing the $continue variable in above to be a temporary variable results in the (if:) condition always being true.
You're right, greyelf; I'll make a point of mentioning the version of Harlowe that I'm using, which is v2.
For the loop itself, now: that's what I needed.
Many thanks.
Comments
Harlowe 2.x's implementation of a for loop is designed to iterate through a collection, and I could not find anything in it's documentation to indicate that you could stop that iteration.
You can however use a variable to control if anything is done during that each loop, as the following demonstrates. warning: For reasons unknown, changing the $continue variable in above to be a temporary variable results in the (if:) condition always being true.
For the loop itself, now: that's what I needed.
Many thanks.