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.

Simpler statements if-checks

Quality Example
Worse

"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?"

Simpler

"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?"

Better developer c-like

Quality Example
Better

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

from question "Accepting array input until a certain value is entered"

"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?"

"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"

"In the previous example break is better than goto"

from question "Accepting array input until a certain value is entered"

Cleaner solution

"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"

Graceful l faster

Quality Example
Little more

"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?"

Faster

"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"

Others

Quality Example
Moreso

"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?"

More restrictive

"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"

More

"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)"

Worse

"But break is no better or worse than goto"

from question "Use of goto for cleanly exiting a loop"

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