forEachReversed: Difference between revisions
Jump to navigation
Jump to search
Lou Montana (talk | contribs) m (Text replacement - " |version1= 2.14 |branch= dev" to " |version1= 2.14") |
Lou Montana (talk | contribs) m (Text replacement - "(\|[pr][0-9]+ *= *[^- ]*) *- *T([a-z ])" to "$1 - t$2") |
||
Line 15: | Line 15: | ||
* {{hl|[[Magic Variables#forEachIndex|_forEachIndex]]}}: item's index | * {{hl|[[Magic Variables#forEachIndex|_forEachIndex]]}}: item's index | ||
|p2= array: [[Array]] - | |p2= array: [[Array]] - the array to iterate over | ||
|r1= [[Anything]] - Will return the value of last executed statement | |r1= [[Anything]] - Will return the value of last executed statement |
Revision as of 15:50, 8 November 2023
Description
- Description:
- Executes the given command(s) on every item of an Array in reversed order, compared to forEach.
- Groups:
- Program FlowArrays
Syntax
- Syntax:
- code forEachReversed array
- Parameters:
- code: Code to execute on each array item - available variables:
- _x: iterated item
- _forEachIndex: item's index
- array: Array - the array to iterate over
- Return Value:
- Anything - Will return the value of last executed statement
Examples
- Example 1:
- This command lets you easily iterate through an array from last to first element without modifying the array itself with reverse or using for loop with negative step.
- Example 2:
- Can be useful to walk through array while also deleting items from it, which you couldn't do with forEach as easily:
Won't work with forEach as you might expect it:
- Example 3:
- Deleting items from array with more complex condition than just comparison.
Additional Information
Notes
-
Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note