C# goto

goto statement stops current execution process and starts execution at a specified position.

int ori = 10;
for (int i = 0; i < 5; i++)
{
ori = ori + 5;
if (i == 3) goto pos;
}
pos:
ori += 10; //ori is 40

Using goto statement to jump out of multiple loops.
int ori = 10;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 10; j++)
{
ori = ori + 5;
if (i == 3) goto pos;
}
}
pos:
ori += 10; //175



endmemo.com © 2024  | Terms of Use | Privacy | Home