forEach – Talk

From Bohemia Interactive Community
Jump to navigation Jump to search
No edit summary
No edit summary
Line 24: Line 24:
in ofp, arma and arma2 this code returns the result:
in ofp, arma and arma2 this code returns the result:
  ["a","b","c",1,"a","b","c",2,"a","b","c",3]
  ["a","b","c",1,"a","b","c",2,"a","b","c",3]
[[User:DenV|DenV]] 11:29, 5 April 2010 (CEST)
:And another test:
spawn {
    _c = [];
    _c resize 100000;
    _t = time;
    {
        if ( time != _t ) exitwith {
            hint format ["Facts are facts only when they are supported by facts! time %1 != start time %2", time, _t]
        };
    } foreach _c
}

Revision as of 11:29, 5 April 2010

DenV 09:25, 5 April 2010 (CEST)

>> Plural commands are executed within one frame, so this command might cause performance loss when used on very large arrays or with very complex commands.

Heh, in this case, you have to explain why this code is functional:

0 spawn { 
    {
        player sideChat str _x; 
        sleep 1 
    } foreach [1,2,3] 
}

Obviously, the facts listed in the article is untrue. we should either make additional comments or remove this statement.

>> In ArmA2, the variable _x is always local to the foreach block so it is safe to nest foreach commands.

Heh:

_log = [];
{ 
    { 
        _log set [count _log, _x] 
    } foreach ["a", "b", "c"]; 
    _log set [count _log, _x] 
} foreach [1,2,3]; 
_log

in ofp, arma and arma2 this code returns the result:

["a","b","c",1,"a","b","c",2,"a","b","c",3]

DenV 11:29, 5 April 2010 (CEST)

And another test:
spawn {
    _c = [];
    _c resize 100000;
    _t = time;
    {
        if ( time != _t ) exitwith {
            hint format ["Facts are facts only when they are supported by facts! time %1 != start time %2", time, _t]
        };
    } foreach _c
}