Well, you can't just place a exitWith in the loop to exit the script, since it would just break out of the loop, actually causing the "commander is dead" message and setting timesOver. Thus use exitWith to break out of the loop (like "break" statement in most languages), then ensure that the commander dying effects only occur if healing hasn't already happened.
A small point, but "if (x) then ..." is the same as "if (x == true) then ..." if x is a boolean (true/false). "if (not x) then ..." is the same as "if (x == false) then ...". Generally, when using if with booleans, one would use the former, simpler versions.
_timetowait = _this select 0;
while {_timetowait > 0} do
{
// Break out of the while loop *before* printing any messages (which is after the sleep, when looping), otherwise you could get messages AFTER the commander is healed.
if (healing) exitWith { };
if (_timetowait != 1) then
{
cutText[format["%1 minutes left", _timetowait], "PLAIN DOWN"];
}
else
{
cutText["One minute left", "PLAIN DOWN"];
};
Sleep(60);
_timetowait = _timetowait - 1;
};
// Tell the world that the commander has "died" only if healing hasn't reached him.
if (not healing) then
{
cutText["Our commander is dead... We didn't make it in time.", "PLAIN"];
timesover = true;
PublicVariable "timesover";
};
One alternative to the exitWith would be to use:
while {(_timetowait > 0) and (not healing)} do
This would have the same effect; it is just personal choice (well, OK, certain programming dogmas would favour one technique over the other, but you needn't be too worried about that ;P).