goto

How can I use goto in a switch statement in Objective-C?

对着背影说爱祢 提交于 2019-12-07 03:02:53
问题 In my code I need to be able to jump (goto) a different case within the same switch statement. Is there a way to do this? My code is something like this: (There is a lot of code I just left it all out) switch (viewNumber) { case 500: // [...] break; case 501: // [...] break; . . . . . case 510: // [...] break; default: break; } Thank you for your time! -Jeff 回答1: It's generally very bad practice to unconditionally jump like you're asking. I think a more readable/maintainable solution would be

GOTO statement in C#.NET

自闭症网瘾萝莉.ら 提交于 2019-12-07 02:10:25
问题 try {... block: .... } catch{ ..} GOTO block ... .... finally{...} Will goto executes in this case?? 回答1: It won't compile because of ' GOTO block ' instead of ' goto block; ' and even if it was right it won't compile because C# specifications states (§8.9.3): The target of a goto identifier statement is the labeled statement with the given label. If a label with the given name does not exist in the current function member, or if the goto statement is not within the scope of the label, a

How GOTO statement in Groovy?

社会主义新天地 提交于 2019-12-06 06:49:48
问题 I saw this nice blog post about a Scala continuations that 'emulates' a GOTO statement in the Scala language. (read more about Continuations here) I would like to have the same in the programming language Groovy. I think it's possible within a Groovy compiler phase transformation. I'm working on an Domain-Specific Language (DSL), and preferred embedded in Groovy. I would like to have the GOTO statement, because the DSL is an unstructured language (and is generated from workflow diagrams). I

How to use goto to break a nested loop

狂风中的少年 提交于 2019-12-06 02:19:44
问题 How can I use a "goto" statement to break out of a loop for(i = 0; (i < 9); i++) { for(j = 0; j < 9; j++) { //cout << " " << Matrix[i][j]; //cout << "i: " << i << endl; if(Matrix[i][j] == 0) { //temp = 10; [goto] ; //break; } } } I wanted to keep the values at which i and j were when I left the nested for loop. How can I use a goto statement for that? 回答1: Like this: int i,j; for(i = 0; i < 9; i++) { for(j = 0; j < 9; j++) { //cout << " " << Matrix[i][j]; //cout << "i: " << i << endl; if

Algorithm for rewriting modified goto semantics

烈酒焚心 提交于 2019-12-05 08:45:50
I've got an large bunch of legacy code in an old self-conceived scripting language that we compile/translate into javascript. That language has a conditional jump, jumping to a label. Difference to common goto statement is, that no backward jumps are possible. There are no nested if statements nor loops in that language. As goto does not exist in javascript, I'm looking for an algorithm that transforms goto mylabel and mylabel: into semantically equivalent structure. I thought of using ifs but found it not trivial because of the arbitrary nesting of the goto labels. Example: if cond1 goto a do

GOTO statement in C#.NET

流过昼夜 提交于 2019-12-05 07:56:44
try {... block: .... } catch{ ..} GOTO block ... .... finally{...} Will goto executes in this case?? It won't compile because of ' GOTO block ' instead of ' goto block; ' and even if it was right it won't compile because C# specifications states (§8.9.3): The target of a goto identifier statement is the labeled statement with the given label. If a label with the given name does not exist in the current function member, or if the goto statement is not within the scope of the label, a compile-time error occurs. This rule permits the use of a goto statement to transfer control out of a nested

How can I use goto in a switch statement in Objective-C?

萝らか妹 提交于 2019-12-05 07:13:46
In my code I need to be able to jump (goto) a different case within the same switch statement. Is there a way to do this? My code is something like this: (There is a lot of code I just left it all out) switch (viewNumber) { case 500: // [...] break; case 501: // [...] break; . . . . . case 510: // [...] break; default: break; } Thank you for your time! -Jeff It's generally very bad practice to unconditionally jump like you're asking. I think a more readable/maintainable solution would be to place the shared code in a method and have multiple cases call the method. If you really want to, you

How do you implement goto in F#?

点点圈 提交于 2019-12-05 06:36:00
All my favorite languages have a goto command. That is, you can create a label, and then later interrupt the flow of the program to go to the label. One of the more useful applications of this construct is to create an infinite loop, like this: start: goto start Unfortunately, if I undertstand the compiler errors correctly, I can't use this same syntax in F#. So, since it doesn't seem to be supported natively, how can I implement the goto command in F#? Surely, F# is a powerful enough language to implement a feature as simple as this. Other languages, such as Javascript, which do not natively

Labels - break vs continue vs goto

守給你的承諾、 提交于 2019-12-04 23:55:09
问题 I understand that: break - stops further execution of a loop construct. continue - skips the rest of the loop body and starts the next iteration. But how do these statements differ when used in combination with labels? In other words what is the difference between these three loops: Loop: for i := 0; i < 10; i++ { if i == 5 { break Loop } fmt.Println(i) } Output: 0 1 2 3 4 Loop: for i := 0; i < 10; i++ { if i == 5 { continue Loop } fmt.Println(i) } Output: 0 1 2 3 4 6 7 8 9 Loop: for i := 0;

Go To Statement Considered Harmful?

只谈情不闲聊 提交于 2019-12-04 23:00:44
If the statement above is correct, then why when I use reflector on .Net BCL I see it is used a lot? EDIT: let me rephrase: are all the GO-TO's I see in reflector written by humans or compilers? The above isn't really correct - it was a polemical device used by Dijkstra at a time when gotos were about the only flow control structure in use. In fact, several people have produced rebuttals, including Knuth's classic "Structured Programming Using Goto" paper (title from memory). And there are some situations (error handling, state machines) where gotos can produce clearer code (IMHO), than the