Control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated.
Questions tagged [control-flow]
13 questions
1330
votes
14 answers
Where did the notion of "one return only" come from?
I often talk to programmers who say "Don't put multiple return statements in the same method." When I ask them to tell me the reasons why, all I get is "The coding standard says so." or "It's confusing." When they show me solutions with a single…

fredoverflow
- 6,854
- 8
- 39
- 46
20
votes
7 answers
Should "else" be used in situations where control flow renders it redundant?
I sometimes stumble upon code similar to the following example (what this function does exactly is out of the scope of this question):
function doSomething(value) {
if (check1(value)) {
return -1;
}
else if (check2(value)) {
return…

rhino
- 357
- 1
- 7
3
votes
1 answer
What's the OOP way of dealing with a flow control heavy application?
I'm refactoring a huge WPF application whose complexity stems from the way it deals with flow control. It has a lot of "tiny business rules" that make it really difficult to make a modification without breaking something. These rules are things…

Pepedou
- 133
- 5
3
votes
4 answers
Optimistic & Pessimistic Programming - Ensuring multiple tasks are called only once for specific record
Let's say you have 10 database records which you need to process in the following way:
Start
Pull 2 records from the database with the 'Processed' flag set to 'false'
Call the external web service with the custom data from this 2 records.
Update…

HABJAN
- 171
- 8
3
votes
1 answer
Flow Chart - While Loops process
I'm having difficulties understanding whether or not this is the right process to use for a flow chart which illustrates the processes involved in an algorithm.
For this, assume the following:
A 1D X = [0, 1, 2, 3,........] data block is split into…

Phorce
- 209
- 1
- 5
- 9
2
votes
1 answer
How do I achieve non-linear non-dependent control flow using Promises (in server-side ES6)
Coming over from the Java world, I am having trouble translating a multi-threaded approach to IO to the ES6 Promises concept of aysnc IO. Many of the examples I have seen on promises show a linear flow.
promiseFunction
…

Michael Plautz
- 394
- 1
- 10
2
votes
1 answer
How to compute whether it is guaranteed the variable is set?
Assuming declarations are expressions consider such code:
if ((var x = foo()) and (var y = x)) or (var z = bar()) then
println(z);
end
The reference to x is OK, because at this point x has to be set, but the reference to z (in println) is not. It…

greenoldman
- 1,506
- 1
- 14
- 27
1
vote
1 answer
How a Control-Flow Graph looks with many (Nested) Functions
From what I can remember the Control-Flow Graphs for which I have seen images have mostly been of single functions. So basically just statements with perhaps looping. But I am wondering what a control-flow graph would look like for a function, which…

Lance
- 2,537
- 15
- 34
0
votes
2 answers
Is this a case where 'else' is inevitable?
I am writing some code that enables / disables a certain kind of hardware function. To enable it on, I have to call some methods, and to disable it, some others.
Of course I want this code to be clean, so I try to keep the use of if/else to a…

Bart Friederichs
- 779
- 1
- 5
- 11
0
votes
2 answers
Creating a control flow graph for a given function
Given is a short Java function and I like to create a control flow graph for it but I'm not sure if it's fine like that? Because I left some things away such as variables that have already been created with the function together (int[] A, boolean[]…

eyesima
- 119
- 1
- 4
0
votes
1 answer
Control flow testing in white box - static or dynamic?
Yesterday I asked a question that happened to have another meaning inside. I can see that Control/data flow is often mentioned to be static analysis (when tools is used) or dynamic analysis testing in terms of white box testing. Could it be that…

John V
- 4,898
- 10
- 47
- 73
-2
votes
1 answer
Why is the If-then-else, while loop and for loop a structured programming control structure?
When defining McCabe's essential complexity, the idea of a structured programming control structure is present. I don't understand why an if-then-else, a while loop or a for loop can be reduced to a single statement such that it's cyclomatic…

Cedric Martens
- 219
- 1
- 9
-2
votes
1 answer
Problem on recursion
void function(int x){
if(x<=0)
return;
function(x--);
}
This is a recursion function which is called with the value of x = 20.
The Recursive call will take place in this way
function(20)...function(19).......function(0)
Each…

aswal94
- 11
- 4