goto

Automated GOTO removal algorithm

自作多情 提交于 2019-12-03 09:21:24
问题 I've heard that it's been proven theoretically possible to express any control flow in a Turing-complete language using only structured programming constructs, (conditionals, loops and loop-breaks, and subroutine calls,) without any arbitrary GOTO statements. Is there any way to use that theory to automate refactoring of code that contains GOTO s into code that does not? Let's say I have an arbitrary single subroutine in a simple imperative language, such as C or Pascal. I also have a parser

How do I get GDB to break out of a loop?

纵饮孤独 提交于 2019-12-03 08:16:53
问题 I can tell GDB to return from a function immediately with return , and call a function with call myFunction . But how do I get it break out of the current loop? i.e. to act as if it's hit a break; statement. Is jump myfile.c:<linenumber> the way to do this? 回答1: jump looks like what you want. See Continuing at a Different Address 回答2: You can use - until to make the loop end. You should give it at the end of the loop. Useful if you no need step into iterate a loop. 回答3: I do this: 1. do a

only do if day… batch file

与世无争的帅哥 提交于 2019-12-03 07:01:55
hello i got a batch file, something like this: if %day%==monday, tuesday, wednesday, thursday, friday ( goto yes ) else ( goto no ) Now i know the first line won't work. What i actually want to happen: It automatticly checks which day it is. If it is Monday to Friday, it has to go to 'yes', otherwise (saturday/sunday) to 'no'. How to do this? I ran across this online. Tested, and it works. Returns the day as an integer, which you can still work with. @For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @( Set Month=%%A Set Day=%%B Set Year=%%C ) @echo DAY = %Day% @echo Month = %Month% @echo

How to break out of multiple loops at once in C#?

寵の児 提交于 2019-12-03 06:26:27
问题 What if I have nested loops, and I want to break out of all of them at once? while (true) { // ... while (shouldCont) { // ... while (shouldGo) { // ... if (timeToStop) { break; // Break out of everything? } } } } In PHP, break takes an argument for the number of loops to break out of. Can something like this be done in C#? What about something hideous, like goto ? // In the innermost loop goto BREAK // ... BREAK: break; break; break; 回答1: Extract your nested loops into a function and then

Why does Go have a “goto” statement

心已入冬 提交于 2019-12-03 02:54:15
问题 Google's Go language is a new language. Therefor I was surprised to find that it has a 'goto' statement. I've always been taught that 'goto' statements are a thing of the past and evil for it occludes the actual flow of a program. Function (or methods if you will) are always a better way of controlling flow. I must be missing something. Why did Google include it? 回答1: When we actually check Gos source code ( the standard library ), we can see where goto s are actually well applied. For

Continue Considered Harmful? [closed]

笑着哭i 提交于 2019-12-03 02:29:55
Should developers avoid using continue in C# or its equivalent in other languages to force the next iteration of a loop? Would arguments for or against overlap with arguments about Goto ? I think there should be more use of continue! Too often I come across code like: for (...) { if (!cond1) { if (!cond2) { ... highly indented lines ... } } } instead of for (...) { if (cond1 || cond2) { continue; } ... } Use it to make the code more readable! Is continue any more harmful than, say, break ? If anything, in the majority of cases where I encounter/use it, I find it makes code clearer and less

Automated GOTO removal algorithm

删除回忆录丶 提交于 2019-12-02 23:28:50
I've heard that it's been proven theoretically possible to express any control flow in a Turing-complete language using only structured programming constructs, (conditionals, loops and loop-breaks, and subroutine calls,) without any arbitrary GOTO statements. Is there any way to use that theory to automate refactoring of code that contains GOTO s into code that does not? Let's say I have an arbitrary single subroutine in a simple imperative language, such as C or Pascal. I also have a parser that can verify that this subroutine is valid, and produce an Abstract Syntax Tree from it. But the

How to break out of multiple loops at once in C#?

左心房为你撑大大i 提交于 2019-12-02 19:54:45
What if I have nested loops, and I want to break out of all of them at once? while (true) { // ... while (shouldCont) { // ... while (shouldGo) { // ... if (timeToStop) { break; // Break out of everything? } } } } In PHP, break takes an argument for the number of loops to break out of. Can something like this be done in C#? What about something hideous, like goto ? // In the innermost loop goto BREAK // ... BREAK: break; break; break; Extract your nested loops into a function and then you can use return to get out of the loop from anywhere, rather than break. Introduce another control flag and

Why does Go have a “goto” statement

五迷三道 提交于 2019-12-02 16:27:22
Google's Go language is a new language. Therefor I was surprised to find that it has a 'goto' statement. I've always been taught that 'goto' statements are a thing of the past and evil for it occludes the actual flow of a program. Function (or methods if you will) are always a better way of controlling flow. I must be missing something. Why and when is using 'goto' a good idea? Or why did Google include it? Kissaki When we actually check Gos source code ( the standard library ), we can see where goto s are actually well applied. For example, in the math/gamma.go file, the goto statement is

Why this example is stuck in an infinite loop in C? [duplicate]

牧云@^-^@ 提交于 2019-12-02 14:39:37
问题 This question already has answers here : Why is scanf() causing infinite loop in this code? (15 answers) Closed 5 years ago . In the example below, if I enter a character in Mac OS X terminal, the program will get stuck in an infinite loop, printing Please enter a number: line after line and never allowing the user to input anything. What's wrong with this code? What is the fix? I want to change the code in a way that if a number is not entered, the user is prompted with an error message and