When using fast enumeration, is there a way to exit early, i.e. before going through every element in the array?
for (element in myArray)
{
//is there a way to exit before running through every element in myArray?
}
break;
will exit any for
, while
, or do
loop.
For example:
for (element in myArray)
{
if (someExitCondition)
{
break; /* leave now */
}
}
Read this:
http://msdn.microsoft.com/en-us/library/wt88dxx6(v=vs.80).aspx