Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use goto statement in objective c?

I want to skip some line of code by checking if condition in the same method. I used goto statement but it showed "cannot jump from this goto statement to the label". Is there any other way I can skip code? what I do is..

if(condition)
       goto skipped;
 //code to skip
 //code to skip

skipped:
 //code to execute
like image 880
Jashu Avatar asked Feb 06 '16 05:02

Jashu


People also ask

How do you use goto statement?

The use of goto statement may lead to code that is buggy and hard to follow. For example, one: for (i = 0; i < number; ++i) { test += i; goto two; } two: if (test > 5) { goto three; } ... .. ... Also, the goto statement allows you to do bad stuff such as jump out of the scope.

How does goto work in C?

The goto statement is a jump statement which is sometimes also referred to as unconditional jump statement. The goto statement can be used to jump from anywhere to anywhere within a function.

Can we use goto in C?

A goto statement in C programming provides an unconditional jump from the 'goto' to a labeled statement in the same function.

Does goto have scope?

In the C programming language, the goto statement has fewer restrictions and can enter the scope of any variable other than variable-length array or variably-modified pointer.


1 Answers

There are surely legitimate uses for goto, so I think this deserves a proper answer:
Some possible reasons why you might be failing:

  • Scope issues (Trying to jump to new functions, etc)
  • Jumping across declarations/destructors

Read more : http://en.cppreference.com/w/cpp/language/goto

like image 117
Mars Avatar answered Nov 01 '22 14:11

Mars