Loop Else#
An else
can be added after a loop, which has special meaning related to the break statement.
The code in the body of the else
will run in the condition that the loop ends WITHOUT a break statement running.
for(enemy : Screen->NPCs)
{
if(Distance(Hero->X, Hero->Y, enemy->X, enemy->Y) < 64)
{
printf("Found an enemy %d near the Hero!\n", enemy->ID);
break;
}
}
else
{
printf("Found no enemies near the Hero!\n");
}