The control-structures tag has no wiki summary.
4
votes
2answers
102 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 ...
3
votes
3answers
153 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'):
public function getter($type = null, $key = ...
1
vote
2answers
90 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
99 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 in optimizations on the control ...
1
vote
1answer
159 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.
def ...
3
votes
1answer
131 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
$id=0;//initialized in case of no result
$r=mysql_query(SQL);
if($r && mysql_num_rows($r)>0){
...
5
votes
3answers
262 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 based on current culture (arabic or ...
5
votes
1answer
260 views
IF ELSEIF - I need a Cleaner way of writing this code
I need a cleaner way of writing the following piece of code:
For Each value As String In collection
If (value = "MYKEY1") Then
If (TabPageIsVisible(tpImportHealth)) Then
...
2
votes
4answers
326 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 ...
12
votes
8answers
565 views
Is there a better way to do this than an if statement?
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 ...
2
votes
2answers
775 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
355 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:
if( $blnLogged && isset( $_POST['postReview'] ) )
{
if( ...
7
votes
2answers
360 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). ...