Home   Help Search Login Register  

Author Topic: Using exitwith in sqf files  (Read 873 times)

0 Members and 1 Guest are viewing this topic.

Offline Gielovic

  • Contributing Member
  • **
Using exitwith in sqf files
« on: 10 Nov 2007, 16:40:38 »
Hey guys,

I have somthing like this in my sqf script
Code: [Select]
FUNCTION = {private[blabla];
while(true) do{somthing};
[b]???if(true) exitWith{}???[/b]
}; //end

[blabla] call FUNCTION;
[balbal] call FUNCTION;
:
:
[blkajd] call FUNCTION;

do i need to insert an exitwith in the end of the function ( like i did in bold ) to let it terminate or does it do that automatically?

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Using exitwith in sqf files
« Reply #1 on: 10 Nov 2007, 16:56:20 »
You don't need to terminate a function in any way. The only thing is that the function will always return the value of the last statement in it so I tend to just put nil at the end so that I'm not returning something unexpected (which is the same as a final if (true) exitWith {}).
Code: (returns the new value of var, which may not be expected) [Select]
add5ToVar =
{
    var = var + 5;
};

Code: (returns nil) [Select]
add5ToVar =
{
    var = var + 5;
    nil;
};

Code: (returns nil) [Select]
add5ToVar =
{
    var = var + 5;
    if (true) exitWith {};
};
« Last Edit: 10 Nov 2007, 17:00:01 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)