Break

A break statement is a flow-control feature provided by most programming languages that allows for an early exit from a loop; once a break statement is reached, its enclosing loop is immediately exited.

Goto

In imperative programming, a "go to" statement is an unconditional jump instruction that changes the flow of control to the point of the program referenced by the "go to" statement.



Nested loops worse

Example

"Labeled break like in java would be better than goto for this purpose"

from question  

PHP and the goto statement to be added in PHP 5.3

"But goto is better than break when you have nested loops like that"

from question  

Accepting array input until a certain value is entered

"In the previous example break is better than goto"

from question  

Accepting array input until a certain value is entered

"The idea of saying break out of the nth nested loop is worse than a goto from a structural perspective"

from question  

Why do most/all languages not have a multi-loop break function?

"If you re in a nested loop and need to break out of all loops a goto can make this much cleaner and simpler than break statements and if-checks"

from question  

Is it ever advantageous to use 'goto' in a language that supports loops and functions? If so, why?

"And a break would be better than the goto"

from question  

Scanning Names and weird Strings: Files

"The reason c doesn t have it is that it s even worse than a goto you have to count the nested loops to figure out what it does and it s vulnerable to someone coming along later and adding or removing a level of nesting without noticing that the break count needs to be adjusted"

from question  

How to avoid use of goto and break nested loops efficiently

Statement end intuitively

Example

"As the rule suggests wee should not use more than one break or goto statement in any iteration statement sample code i have tried with nested if statements but it is not a solution to terminate the loop"

from question  

MISRA C 2012 Rule 15.4 There should be no more than one break or goto statement used to terminate an any iteration statement

"The bad we use a break that is little more than a tamed goto something like goto the end of the loop"

from question  

Possible segmentation fault: Am I using the "this->" operator correctly?

"There s not really a graceful way to break out of for l although it is much faster than a goto loop"

from question  

How to reverse strings in a batch file

"I guess the goto is slightly more readable intuitively.;but if you wanted to avoid the goto i think all you d have to do is throw the code in a while true loop and then have a break statement at the end of the loop for a normal iteration"

from question  

Is this goto expressive?

Use developer c-like

Example

"As for your question your use of goto would make me uncomfortable;the only reason that break is less readable is your admittance to not being a strong c++ developer"

from question  

Use of goto for cleanly exiting a loop

"To any seasoned developer of a c-like language break will both read better as well as provide a cleaner solution than goto"

from question  

Use of goto for cleanly exiting a loop

"Use break and continue as necessary;i can nearly guarantee you any situation in which you are utilizing goto there is a better alternative"

from question  

What to use instead of Goto Statements?

"Nevertheless in my opinion break is not much better than goto its both not a good programming style"

from question  

In what case would the use of a T-SQL GOTO statement be acceptable?

Others

Example

But actually break has more resemblance to return both instructions jump out of a block of code which is pretty much structured in comparison to goto

from question  

Do {...} while(false)

It is the equivalent of a goto but is more restrictive in that labels may be used only in break or continue statements

from question  

I found this code and wanted to know the proper definition of the "test:" part

In the cleanup even in normal case scenario i would regard the use of goto as being clearer than the do while 0 constructs among other things because the target labels themselves practically cry out look at me far moreso than the break and do while 0 constructs

from question  

Valid use of goto for error management in C?

But break is no better or worse than goto

from question  

Use of goto for cleanly exiting a loop

Sometimes the break condition is more natural and sometimes the goto is clearer

from question  

Leaving switch in while(1)

Mysteriously when you spell the goto as while and break the goto is no longer morally wrong

from question  

Return to first element in foreach

Back to Home
Data comes from Stack Exchange with CC-BY-SA-4.0