How can I transfer control to a specific line in Swift code?
In Objective-C I would do something like the following, using goto
if(a==b)
{
goto i123;
}
else
{
goto i456;
}
NSLog(@"the not reachable point");
i123:
NSLog(@"line 123 is here");
int j = 5;
int x = 2+j;
i456:
NSLog(@"line 456 is here");
The only control transfer statements in Swift I could find were continue
, break
, fallthrough
, and return
continue
and break
only work with loops; return
and fallthrough
don't transfer control this way.
What can I use?
EDIT:-
Julien__'s answer didn't actually solve my problem but it could be the only available option right now. so i have accepted the answer by Julien__
x
after jumping toi456:
. One goal of the Swift language was that the compiler can check if all variables are initialized before being used. – Delrosariogoto
was originally a workaround for a program without subroutines. – Unguinousgoto
is bad practices - in any language you make the code less readable – Mudlark