If it does support, can I ask what is the syntax? I tried something like the following, but it does not work.
function Update () {
outter: for(var i:int=0;i<10;i++){
if(i==8)break outter;
}
}
If it does support, can I ask what is the syntax? I tried something like the following, but it does not work.
function Update () {
outter: for(var i:int=0;i<10;i++){
if(i==8)break outter;
}
}
As far as I know, Unity supports whats in .NET already (sorry MONO).
So if you have this in .NET/MONO its available.
But I must say, that its a bit bad algoritm if you really need that approach?
Cant you write it more clean/nice? I’ll help you if you want.
From what I see/understand you need to skip the rest of the for-loop if you find something is true inside it? this could be a seek function or something else.
Perhaps you shouldnt use a FOR LOOP for this. As WHILE-loop seems more logical.
But if you want to keep using the FOR-loop just end it with i=max … i=10 and then a “break”. That ought to skip the rest of the function.
You dont want it to go back and do the outter again, as the Update function in Unity is called every single frame, sometimes even twice.
So if you need to make a large computation or AI or something with this, you can use Co-Routines instead. Look for Yield and StartCoroutine in script reference and all the questions in here.
If you wanted to do a WHILE-loop, it could look something like this:
bool isFound = false;
int i=0;
while (!isFound && i<10)
{
if(i==8) // bad check as i is already part of the while-condition?
{
isFound=true;
break; // this will break out of the current while-loop{} and validate the while-statement which now is false.
}
// this makes the WHILE-terminate sooner or later
i++;
}
C# and UnityScript doesn’t support direct jumps and labels. Mono / .NET does support jumps but just on IL-level. All high-level languages (that i know) abandoned jumps because they break the scope rules and as a serious programmer you shouldn’t even think about using them
break
or continue
is something totally different.
break
will leave the current block and continue
will terminate the current iteration and go on with the next iteration in a loop.
label-based programming is not a good programming style. Maybe you can go a bit more in detail what you want to achieve so we can find a solution.