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

-2
votes
0answers
29 views

understand operator precedence [migrated]

Was fixing bug in our code and found this weird function that was misbehaving: ...
6
votes
3answers
86 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
201 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
426 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
958 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
209 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
139 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
651 views

Python - 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
130 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
377 views

Should I use a ternary expression in this case?

Is a ternary expression ok in this case: ...
4
votes
3answers
577 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
799 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. ...
35
votes
4answers
4k 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
452 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 ...
26
votes
3answers
3k views

Cleaner usage of the ternary “?” operator

I've recently been doing some mods to some old code I've been maintaining for a couple of years now. As part of a wider set of scripts using YAHOO YUI 2.2 (yes, that old) for dialog-style panels, I ...