Boolean expressions that can involve logical operators, used for branching execution paths, which increases cyclomatic complexity.

learn more… | top users | synonyms

1
vote
1answer
28 views

Adding additional function if condition is met

Here's my scenario: In case the table has class 'trans' - run dataTable() and ...
6
votes
6answers
199 views

Conditional statements relating to hospital management

It works just fine, but is there any other way to write this shorter? Nurses are only available to intensive care patients (room I) and TV's and telephones are only available to non intensive care ...
9
votes
4answers
830 views

Constructor to transform an Outlook contact into a Dynamics CRM contact

This is my constructor to transform an Outlook contact into a Dynamics CRM contact: ...
2
votes
2answers
29 views

What do you think about this custom syntax? [closed]

I'm making a programming language and I've got the basis of a virtual machine working. The next step to is design the actual syntax for the language. I'd just like to know if whether the example ...
7
votes
6answers
1k views

Shorter way to write multiple if-then-else-if

if($row['best']){ $id = $row['best']; } elseif($row['average']){ $id = $row['average']; } elseif($row['bad']){ $id = $row['bad']; } If ...
2
votes
3answers
215 views

Coding style preference if (aPtr), if (aPtr != NULL), or if (NULL != aPtr) [closed]

I understand that as far as the compiler is concerned, the following lines are equivalent. if (aPtr) {...} if (aPtr != NULL) {...} if (NULL != aPtr) {...} ...
2
votes
2answers
94 views

How to format embedded if statements in JavaScript

What would be the best way to format this code? It looks a bit messy to me in regards to indentation etc. ...
1
vote
1answer
23 views

Remove nodejs/browser specific code in library

I'm the maintainer of the following library on github: https://github.com/edi9999/docxtemplater/blob/master/coffee/docxgen.coffee I want to maintain a library that works on node and in the browser, ...
9
votes
3answers
156 views

Thinking outLoud conditional if statement vs. for statement

I have been working with java for a little more than a year. I recently have built a tic tac tow game as an assignment for my java class. After instructor graded it, he wrote a comment around my ...
16
votes
5answers
2k views

Tic Tac Toe computer AI

I am creating a TicTacToe game for my college project, and when I finished the code for computer AI, I ended up with a big chunk of code. It allows the computer to make the winning move, stopping the ...
6
votes
6answers
268 views

To update or to delete? That is the Query

I'm currently developing a method which performs an update of some data; much like the following simplified logic: ...
16
votes
6answers
2k views

Are the following IF statements acceptable?

I have the following code: ...
6
votes
5answers
1k views

Movement code from a game

Could you suggest ways of writing this code better? ...
3
votes
1answer
93 views

Use if/else/elif conditionals to write a basic Rock Paper Scissors game

I have the following code for the Rock, Paper, Scissor game. The code works fine in Python 2.7. Are there other more concise, more readable, or more pythonic ways of solving this problem in Python? ...
10
votes
3answers
125 views

Refactoring if-else structure with elements of dict

I have code which gets data from a POST request (request.form dict), compares with corresponding attribute in object ...
7
votes
4answers
1k views

Password checker in PHP

I have written a password checker using PHP, consisting of many if else statements. Is there any possible way to shorten this code? ...
4
votes
1answer
127 views

How can I reduce the number of nested if statements in this code?

The application I'm building can accept two types of updates: Application Update and Parameter Updates. If there is an application update, then parameter updates can be ignored. This is the code that ...
4
votes
2answers
57 views

Is there a way to shorten a set of conditionals like this?

I have a long set of IF statements that basically set a null object Value to 0, I feel that because i am doing the same action each time their has to be a simple ...
6
votes
2answers
65 views

Nested trial and error in if-else condition

Using Rails 3.2, I have the following: ...
3
votes
3answers
127 views

Cleaning if-statements in job applicant email system

I just wrote this and don't like how bulky it is, also given the fact I will have to add at least another if statement. I was going to switch it to a case ...
1
vote
2answers
66 views

Reducing cyclomatic complexity in a simple string concatenation

I have written the following function that takes an address object and builds a string using the object properties. It will later be used to display a tooltip ...
4
votes
2answers
95 views

Alternative to multiple if statements

I have a function that needs to evaluate some parameters to determine if they're valid or not. They all need to be evaluated individually, so I have some code like below. ...
2
votes
2answers
68 views

Conditional functions or multiple similar definitions?

In my program(C++), I'm going to use callback functions to process input from the keyboard and mouse and constantly draw a scene. How these functions process information will change depending on the ...
10
votes
2answers
351 views

Simplifying conditional statements for transaction code

I have below code in one function: ...
3
votes
1answer
40 views

Creating objects to be added to a list

When creating objects to be added to a list in Python, we can avoid the if statement by changing our create_object function to ...
5
votes
3answers
180 views

if statements or eval?

I'm wondering about the following code: ...
12
votes
2answers
439 views

Simpler boolean truth table?

I'm doing a CodingBat exercise and would like to learn to write code in the most efficient way. On this exercise, I was just wondering if there's a shorter way to write this code. ...
15
votes
9answers
2k views

Making these conditions shorter

The problem I'm dealing with is the length of my code. I have lots of code like this: ...
-1
votes
3answers
165 views

An exit condition for a do-while loop using lists [closed]

I have an integer list l and a predefined integer value row (which is never manipulated inside the code). If value of row is 5, then I want the loop to exit if ...
4
votes
2answers
81 views

How to make a program that lies one-third of the time?

I am supposed to take this code (that I made): ...
2
votes
1answer
54 views

How can these if-else statements be made more efficient?

I am using the cURL tool in MATLAB 2013b with Ubuntu to download a whole bunch of files. The files have one of three possible versions: 1.0.0, 2.0.0, or 2.1.0. Using the HTTP, I first check the ...
12
votes
5answers
879 views

Condense multiple if statements with or operators?

I created a weather widget in JavaScript that requests the current weather from Yahoo. The weather request returns a code which corresponds with a current weather image. I don't like Yahoo's images, ...
4
votes
2answers
329 views

Simplifying `if` statements in Tic Tac Toe function

I'm currently trying to improve my coding skills, so I'm trying to code a Tic Tac Toe game. At one point a "win check" is needed.I'm using this code to check: ...
3
votes
3answers
593 views

Multiple lines of code in if statement without curly braces [closed]

I have used multiple lines of code in one if condition without using curly braces, which is executing properly. So what is the main necessity of using curly braces ...
4
votes
2answers
291 views

How bad is duplicating a code block? [closed]

Is it preferred to do: if(a) { if(b) { //some statement(s) } } else if(c) { //some statement(s) (the same ones as in the other block) } or ...
2
votes
2answers
96 views

switch (true) as alternative to else if

I've seen usage of switch(true) multiple times and have used it myself today instead of multiple elseif`s. Here is the case I ...
-1
votes
2answers
66 views

Common factor in some cases [duplicate]

I have this code: ...
3
votes
1answer
63 views

How to make this calender program simpler/optimized?

I've made a working calendar program, BUT I believe it's extremely inefficient. I think I have way too many else if statements: ...
12
votes
4answers
427 views

Basic Pokedex using if-else statements

Our instructor told us to create a basic Java program using everything we've learned in class thus far (basic prints, selection structures, looping, GUI, arrays, etc) and being a Pokemon fan, I ...
6
votes
4answers
3k views

null/undefined checking for checking seats

This looks pretty messy (need to reduce nesting I feel). I need a check an input for a seat, but I can't guarantee it has a value (one may not be chosen for example). If the seats aren't in a certain ...
1
vote
2answers
135 views

Which PHP code is faster?

Time is very important from times immemorial. Doing great things and making it happen in less time is more important as it can mean less effort. So I really like to know which way is faster and more ...
3
votes
1answer
198 views

How to refactor those ugly conditional statements?

Context: a console application takes as an argument either a .cs file or a directory. If it's a .cs file, it scans it; if it's a directory, it scans all .cs files within the directory. A simplified ...
7
votes
2answers
176 views

Reasonable use of the comma operator?

I've just posted this solution in my review of @adrienlucca's question, which is to read three rows of six tab-separated doubles. ...
34
votes
8answers
4k views

How can I improve this series of if/else statements?

What are some ways I can improve the following code? Sorry if the question is too generic. I am new to programming and this is for practice. ...
6
votes
4answers
309 views

Organizing semaphores into a pyramid

My homework was to organize semaphores into a pyramid. The task was accomplished, but I ended up with this long ugly conditional and was wondering if anyone can see a better way/algorithm to ...
2
votes
2answers
85 views

Multiple if conditions in one block - looking for faster and more efficient code

i am looking for a faster and more efficient way of this code. What the code does is simply compares message context of (user, application, service and operation) and compares it with some rules. ...
3
votes
2answers
354 views

Password checker containing many conditional statements

Can this be shortened/improved? I'm trying to make a password checker in Python. Could the ifs be put into a for loop? If so, ...
2
votes
3answers
124 views

Comparing and assigning strings

Would you please run through this code and provide your comments? ...
1
vote
0answers
121 views

Backbone/ChaplinJS view with various template

I have ChaplinJS View, with template which varies according to the condition. I try to avoid switch statements, but i think its messy at this moment. What can you advise? ...