Within an imperative programming language, a control flow statement is a statement whose execution results in a choice being made as to which of two or more paths should be followed.

learn more… | top users | synonyms

0
votes
0answers
4 views

Decision Table for a Movement AI in a Game

I posted a question on Stack Overflow about how to implement Decision Tables in Objective-C after reading about them for the first time in chapter 18 of Code Complete. Nobody provided an answer, so ...
2
votes
1answer
99 views

Sum the Multiples of 3 and 5

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below N. ...
7
votes
2answers
92 views

Test string if numeric

I want to implement the following function: ...
2
votes
1answer
80 views

Rendering a history list of shows with different options

I have some PHP code I'm working on which contains 2 queries and I need to set extra conditions for 2 out of 3 view options and one less query for 1 out of 3 view options. Basically, I'm rendering a ...
4
votes
1answer
71 views

Generator expression in combination with StopIteration: kind of a hack?

The first piece of code should cover the standard expected data. But as you can easily see, the data not always conveys to this standard. The code works great but I wonder if this is thought be a ...
5
votes
3answers
216 views

Simplifying and optimizing chat logger

I'm developing a Java EE project which uses Redis through the Jedis library. I'm retrieving the chat history of a particular channel from the servlet context and if absent, from Redis. The PMD ...
1
vote
2answers
106 views

Conditional concatenation

I want to do a conditional concatenation. My issue is at the end of the for-loop. I have all variables starting with \n for removing this, and I need to strip out ...
-3
votes
2answers
274 views

What is better and faster? Should I use is_null or $var === null in a if statement? [closed]

I was thinking about is_null and $var === null in my if control structures. Here is a small ...
10
votes
6answers
2k views

Is the new version of this code more difficult to read and understand than the original? How can it be improved?

I was asked to do a code review for the following block of code. It implemented a bug fix to prevent some values being added to some drop down lists depending on the user's domain, in an ASP.NET ...
1
vote
2answers
88 views

Code structure for loop which requires peeking at the next element

The purpose of this code is important, so here's a quick rundown. This code runs controls a physical machine which utilizes a camera and a moving stage holding an object to be imaged. Imaging can be ...
38
votes
15answers
3k views

Cleaner way to code BOOL×BOOL→ENUM mapping?

Does this part look clean enough? Any suggestions on how to make it cleaner? ...
2
votes
2answers
172 views

Whats a better way to do these nested if statements?

I forgot to mention using the result of bar to calculate foo's value in the question I asked here. The function bar only needs to be called if conditionA is true. But when the result of bar ...
6
votes
3answers
395 views

What's a better (DRY) way to do this if statement?

The function bar only needs to be called if conditionA is true. But when the result of bar (...
6
votes
4answers
289 views

Simplify huge chain of if's and else's, some of them quite similar to each other

If anyone could help me simplify this code, it would be greatly appreciated. There are plenty of if's and else's, and someone else told me that using switch/case statements could really clean up the ...
2
votes
1answer
110 views

Readability concerns with literal dictionary lookup vs if-else

I'm having concerns about readability of this piece of code: messages_dict = {'error':errors, 'warning':warnings}[severity] messages_dict[field_key] = message ...
5
votes
2answers
265 views

Understanding the use of for loops as counting loops in homework review [closed]

Newbie here, first time programmer. I have a homework assignment that I am working on. Instructions: Write an application that allows input of an integer n between 1 and 71, and (using a for or ...
4
votes
3answers
189 views

if-construction: which is better/more logical?

I've got a class with a getter method which gets either a whole array or an array item. The array fetched depends on the type given (either 'a' or 'b'): ...
2
votes
2answers
135 views

Feedback on text parsing and control structures

I threw together this C program today to handle a bioinformatics data processing task. The program seems to work correctly, but I wanted to know if anyone has suggestions regarding how the input data ...
2
votes
2answers
108 views

Small: Setting locale

I'm new to Rails/Ruby and I would like to get feedback on my little ApplicationController which is able to detect the visitor's language. I'm especially interested ...
1
vote
1answer
679 views

Dictionary-based dispatch in Python with multiple parameters

Is there a better way to express the dispatch (switch) code without using a lambda? I think I need the lambda to act as an intermediary because the functions have varying numbers of parameters. ...
6
votes
2answers
252 views

Is it bad practice to rely on short-circuit evaluation instead of using the IF control structure?

Examples of where I've started migrating to short-circuit evaluation: PHP ...
6
votes
3answers
346 views

Better way to write this if-else

Each product in my e-commerce website has arabic & english values for title, description & excerpt. I have this method EditProduct to update those values ...
4
votes
1answer
291 views

IF ELSEIF - I need a Cleaner way of writing this code

I need a cleaner way of writing the following piece of code: ...
2
votes
4answers
461 views

Optimising sample solution of task for firstyear students

I'm giving a lecture on basic programming to first-year mathematics students. The programming language is Java (defined by curriculum). Last week I gave the following task: Write a program, that ...
14
votes
8answers
649 views

Is there a better way to do this than an if statement? [closed]

I've written this structure a few times in the course of my career and it always feels that there's a better way. I'm looking at conditional logic for three outcomes. In the first two outcomes, I ...
3
votes
2answers
2k views

PHP Request Class

This class handles HTTP requests. It's a singleton class that parses URI to get the controller, method and parameters and then executes the controller's method. Maybe parseUri should be in another ...
3
votes
2answers
464 views

How do I optimize my PHP if/else code

I generally encounter a lot of if/else. Here is my sample code. I would like to get some suggestions on my code: ...
8
votes
2answers
486 views

Improve control structure for fortran program

I do most of my programming in C/C++ and Perl, but I currently learning fortran. I began by coding up a simple program, something that took me < 5 minutes in perl (see this thread from BioStar). ...