Normally referring to the conditional operator, represented by the characters ? and :, that form a basic conditional expression in several programming languages, also known as inline if. It is used as follows: (condition) ? (value if true) : (value if false).

learn more… | top users | synonyms

6
votes
3answers
969 views

Returning the lowest and highest number based on input

This simple console program prompts the users for a number and returns the lowest and highest numbers from their inputs. It is difficult to add more user inputs, though. How can I make this easier to ...
5
votes
2answers
240 views

Concise nested statements

I really like the ruby ? : syntax for if else statements. However, I'm not sure how to do the following with a nested ...
7
votes
3answers
456 views

Ternary extension method

I created the following HtmlHelper extension method for my Asp.Net MVC Razor views because the ternary syntax sucks when you need to use it intermixed with markup. Is there a better way to write this ...
11
votes
3answers
2k views

Reduce code complexity by applying ternary operator

I have a condition in my code where I need to put a lot of nested else if statements. However, I have managed to reduce some if ...
7
votes
2answers
236 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. ...
4
votes
3answers
161 views

Execute method on ternary operator result?

I have two List<T>s of the same T and a T object. Based on a condition, I want to add ...
2
votes
1answer
63 views

Property getter implementation

I always see something like this: - (NSMutableArray*)items { if (_items == nil) _items = [NSMutableArray array]; return _items; } Recently I ...
2
votes
1answer
1k views

Strip whitespace from strings in list that contains elements of various types

Let's say I have a list that contains strings and integers. The strings can contain leading and trailing whitespace that I'd like to remove. I can't just strip() ...
3
votes
2answers
141 views

An abundance of ternary operators

I'd like to find a way to do what this method does in a cleaner, less hacky looking way ...
8
votes
4answers
405 views

Should I use a ternary expression in this case?

Is a ternary expression ok in this case: ...
4
votes
3answers
1k views

Shorthand if conditional in PHP

(!empty($student->former_name) ? print $student->former_name : ''); I only want to print out the former name if it is not empty, nothing else. I imagine I ...
3
votes
2answers
946 views

Ternary Operator, check if Datetime is MinValue and set value to it. There is a elegant way to do it?

There is a better or more elegant way to do this ? ctroRegistro.DataHoraCriacao is Datetime. ...
38
votes
4answers
5k views

Ternary operation in Java - isn't this abuse?

I think the below code is difficult to understand. I also feel it abuses Java's ternary operator. ...
8
votes
4answers
461 views

Ternary operator and comments

I have a class that spawns threads to process data. I am working on instrumentation code. When the process is started, time = System.currentTimeMillis(); When it ...