I have this code:
foreach(int i in Directions)
{
if (IsDowner(i))
{
while (IsDowner(i))
{
continue;
//if (i >= Directions.Count)
//{
// break;
//}
}
//if (i >= Directions.Count)
//{
// break;
//}
if (IsForward(i))
{
continue;
//if (i >= Directions.Count)
//{
// break;
//}
//check = true;
}
//if (i >= Directions.Count)
//{
// break;
//}
if (IsUpper(i))
{
//if (i >= Directions.Count)
//{
// break;
//}
num++;
//check = false;
}
//if (check)
//{
// num++;
//}
}
}
but I want to have continue for foreach in while loop. how can I do this?
You could
breakout of thewhileloop and move on to the next iteration of the outerforeachloop which will start a newwhileloop:If you had some other code after the
whileloop that you don’t want to be executed in this case you could use a boolean variable which will be set before breaking out of thewhileloop so that this code doesn’t execute and automatically jump on the next iteration of theforachloop: