Questions tagged [control-flow]
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.
15 questions
18
votes
7
answers
4k
views
Is there a reason "replace conditional with table" isn't a standard refactoring?
I'm preparing a lecture where I will start with a many-branched conditional statement and replace it with a table. For example, I could start with:
function getMonthName(monthNumber) {
if (...
0
votes
2
answers
774
views
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,...
0
votes
2
answers
6k
views
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 ...
20
votes
7
answers
3k
views
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 -...
2
votes
1
answer
131
views
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 ...
-2
votes
1
answer
368
views
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
...
3
votes
1
answer
74k
views
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 ...
1353
votes
14
answers
279k
views
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 ...