Skip to main content
added 27 characters in body
Source Link
Quentin
  • 109
  • 3

Here is a generic flowchart of a specific type of control flow:

This control flow cannot be implemented with only control flow structures (if, switch, while, for, do while). You have to either use a goto after one of the conditions, or bend up another structure to simulate it. The latter naturally results in code ranging from slightly weird to awful (for example, the lowerloops that don't actually loop could be implemented as an, infinite looploops with an if/break at Condition 2) to awful (I've seen "no breaksif+break either"-people addconditions in the middle, artificial control flag variables to drive the loopswhich form some kind of state machine, one-off functions that don't actually represent a stand-alone operation...).

The truth is that control flow structures do not cover all possible cases. goto should always be the last ever tool you try to solve a problem, but you shouldn't throw it away from your toolbox lest you want to end up driving a screw in with a hammer.

Here is a generic flowchart of a specific type of control flow:

This control flow cannot be implemented with only control flow structures (if, switch, while, for, do while). You have to either use a goto after one of the conditions, or bend up another structure to simulate it. The latter naturally results in code ranging from slightly weird (for example, the lower loop could be implemented as an infinite loop with an if/break at Condition 2) to awful (I've seen "no breaks either"-people add artificial control flag variables to drive the loops).

The truth is that control flow structures do not cover all possible cases. goto should always be the last ever tool you try to solve a problem, but you shouldn't throw it away from your toolbox lest you want to end up driving a screw in with a hammer.

Here is a generic flowchart of a specific type of control flow:

This control flow cannot be implemented with only control flow structures (if, switch, while, for, do while). You have to either use a goto after one of the conditions, or bend up another structure to simulate it. The latter naturally results in code ranging from slightly weird to awful (loops that don't actually loop, infinite loops with if+break conditions in the middle, artificial flag variables which form some kind of state machine, one-off functions that don't actually represent a stand-alone operation...).

The truth is that control flow structures do not cover all possible cases. goto should always be the last ever tool you try to solve a problem, but you shouldn't throw it away from your toolbox lest you want to end up driving a screw in with a hammer.

Source Link
Quentin
  • 109
  • 3

Here is a generic flowchart of a specific type of control flow:

This control flow cannot be implemented with only control flow structures (if, switch, while, for, do while). You have to either use a goto after one of the conditions, or bend up another structure to simulate it. The latter naturally results in code ranging from slightly weird (for example, the lower loop could be implemented as an infinite loop with an if/break at Condition 2) to awful (I've seen "no breaks either"-people add artificial control flag variables to drive the loops).

The truth is that control flow structures do not cover all possible cases. goto should always be the last ever tool you try to solve a problem, but you shouldn't throw it away from your toolbox lest you want to end up driving a screw in with a hammer.