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

5
votes
3answers
356 views

Would I be better off re-factoring out these switches, in this case?

After I completed writing this code, I started to wonder if the switches should be replaced with a more OOP approach. I originally picked the switch approach because there will never be anymore skill ...
7
votes
1answer
81 views

AI Governor to Play a Strategy Game

I had the idea the other day to implement an artificial intelligence that could play my strategy game. This could be useful in a variety of different ways. For example, the player could "lose ...
10
votes
4answers
926 views

Decision Table for the 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
119 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
105 views

Test string if numeric

I want to implement the following function: ...
2
votes
1answer
90 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
74 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
247 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
155 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 ...
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
89 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 ...
40
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
205 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
401 views

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

The function bar only needs to be called if conditionA is true. But when the result of bar (...
6
votes
4answers
306 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
113 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 ...
4
votes
3answers
191 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
137 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
110 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
772 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
300 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
355 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
293 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
491 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 ...
13
votes
8answers
662 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 ...
2
votes
2answers
472 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
517 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). ...