goto

How to jump to a particular place in the for loop if the if condition is satisfied?

China☆狼群 提交于 2019-12-20 06:07:14
问题 I have some image files. I'm trying to perform some calculations using each file and if a certain condition is met, I'd like to go back to a particular line in the code and run it from there once more. But only just once again. Regardless of whether the if condition is satisfied or not satisfied the second time, I want to go to the next iteration. But, MATLAB doesn't seem to have a goto function and also, using goto implies bad programming so I thought I'd just iterate the for loop twice for

Explanation of switch statement constraints on variably modified types in C standard

﹥>﹥吖頭↗ 提交于 2019-12-19 12:52:11
问题 I'm writing a C compiler, and when I come to the implementation of the switch statement one constraint confused me a lot. Section 6.8.4.2p2 of the standard states: If a switch statement has an associated case or default label within the scope of an identifier with a variably modified type, the entire switch statement shall be within the scope of that identifier. With a footnote: That is, the declaration either precedes the switch statement, or it follows the last case or default label

Goto statements in Java [closed]

北战南征 提交于 2019-12-19 05:09:36
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . I executed the below code in Eclipse, but the GOTO statements in it are not effective. How do I use it? How do I rewrite the above code using the Break and Continue statements without using the goto statement? import java.io.BufferedReader; import java.io.IOException; import java.io

Why is it OK to jump into the scope of an object of scalar type w/o an initializer?

让人想犯罪 __ 提交于 2019-12-19 03:11:47
问题 When I'm reading the C++ standard, it seems that the following code is perfectly fine according to the standard. int main() { goto lol; { int x; lol: cout << x << endl; } } // OK [n3290: 6.7/3]: It is possible to transfer into a block, but not in a way that bypasses declarations with initialization. A program that jumps from a point where a variable with automatic storage duration is not in scope to a point where it is in scope is ill-formed unless the variable has scalar type , class type

Why is it OK to jump into the scope of an object of scalar type w/o an initializer?

依然范特西╮ 提交于 2019-12-19 03:11:01
问题 When I'm reading the C++ standard, it seems that the following code is perfectly fine according to the standard. int main() { goto lol; { int x; lol: cout << x << endl; } } // OK [n3290: 6.7/3]: It is possible to transfer into a block, but not in a way that bypasses declarations with initialization. A program that jumps from a point where a variable with automatic storage duration is not in scope to a point where it is in scope is ill-formed unless the variable has scalar type , class type

Are goto and destructors compatible?

久未见 提交于 2019-12-18 12:20:17
问题 This code leads to undefined behavior: void some_func() { goto undefined; { T x = T(); undefined: } } The constructor is not called. But what about this code? Will the destructor of x be called? I think it will be, but I want to be sure. :) void some_func() { { T x = T(); goto out; } out: } 回答1: Yes, destructors will be called as expected, the same as if you exited the scope early due to an exception. Standard 6.6/2 (Jump statements): On exit from scope (however accomplished), destructors are

Are goto and destructors compatible?

旧时模样 提交于 2019-12-18 12:20:08
问题 This code leads to undefined behavior: void some_func() { goto undefined; { T x = T(); undefined: } } The constructor is not called. But what about this code? Will the destructor of x be called? I think it will be, but I want to be sure. :) void some_func() { { T x = T(); goto out; } out: } 回答1: Yes, destructors will be called as expected, the same as if you exited the scope early due to an exception. Standard 6.6/2 (Jump statements): On exit from scope (however accomplished), destructors are

Is it possible to use goto with switch?

旧巷老猫 提交于 2019-12-18 11:41:28
问题 It seems it's possible with C#, but I need that with C++ and preferably cross platform. Basically, I have a switch that sorts stuff on single criteria, and falls back to default processing on everything else. Say: switch(color) { case GREEN: case RED: case BLUE: Paint(); break; case YELLOW: if(AlsoHasCriteriaX) Paint(); else goto default; break; default: Print("Ugly color, no paint.") break; } 回答1: Not quite but you can do this: switch(color) { case GREEN: case RED: case BLUE: Paint(); break;

Is GOTO considered harmless when jumping to cleanup at the end of function?

南笙酒味 提交于 2019-12-18 03:07:19
问题 The goto statement has been examined at great length in several SO discussions (see this and that), and I certainly don't want to revive those heated debates. Instead, I'd like to concentrate on a single use case of goto s and discuss its value and possible alternatives. Consider the following code snippet, which is common in (at least my own) FSMs: while (state = next_state()) { switch (state) { case foo: /* handle foo, and finally: */ if (error) goto cleanup; break; case bar: /* handle bar,

Is GOTO considered harmless when jumping to cleanup at the end of function?

橙三吉。 提交于 2019-12-18 03:07:11
问题 The goto statement has been examined at great length in several SO discussions (see this and that), and I certainly don't want to revive those heated debates. Instead, I'd like to concentrate on a single use case of goto s and discuss its value and possible alternatives. Consider the following code snippet, which is common in (at least my own) FSMs: while (state = next_state()) { switch (state) { case foo: /* handle foo, and finally: */ if (error) goto cleanup; break; case bar: /* handle bar,