Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [conditional-operator]

The conditional operator is a ternary operator that is part of the syntax for a basic conditional expression in several programming languages. It is also commonly referred to as the ternary operator or inline if. Different languages have different syntax for the same construct, but all select between one of two options based on a condition.

conditional-operator
-1 votes
0 answers
27 views

Switcher on pygame [duplicate]

I've trying do switcher on pygame and faces with one problem. My first switchon to switchoff is working, but but next on dont works this is code this is before first elif this is after Code has ...
Владос Алдос's user avatar
-4 votes
2 answers
91 views

How to simplify this ternary expression? [closed]

I wonder if there is a simpler way to write this, or is it already in it's most basic form? A ? (B && C) : B
Nelu's user avatar
  • 18.2k
1 vote
1 answer
57 views

Ternary operator not working inside Lambda function Ruby

I am trying to write a Lambda function in Ruby, to calculate the nth Fibonacci number. fib = -> (n) { n in [1, 2] ? 1 : fib.[n - 1] + fib.[n - 2] } This gives me the error, ./fib.rb:3: warning: ...
Shirsak's user avatar
  • 57
1 vote
3 answers
83 views

python pandas dataframe select rows with ternary operator

I have what has to be considered a syntax question. I am doing some data scrubbing. My data contains date time fields. The date is always present, but sometimes the time is missing. Like this: 3/1/...
KBD's user avatar
  • 141
-1 votes
1 answer
54 views

dplyr returning NA in new column and not following conditions

I have one data frame about animal sightings (more than 300), with species of whales, dolphins, pinipedes and penguins. And I want to create a new column reino, which would be misticeto for whales, ...
Érika Soares Coelho's user avatar
0 votes
1 answer
54 views

Unexpected token '?' in expression or statement

I'm trying to run a script I didn't write and I'm getting this issue: Unexpected token '?' in expression or statement. The line of code causing this is: $configuration = $Env:ASPNETCORE_ENVIRONMENT -...
Jan Kadera's user avatar
6 votes
1 answer
212 views

Why does this ternary generate more Assembly than an equivalent if?

So someone on a forum asked why this C function (which I added const and restrict to, just in case): void foo(int *const restrict dest, const int *const restrict source) { *dest = (*source != -1) ?...
MyNameIsTrez's user avatar
15 votes
2 answers
545 views

Moving after copying in assignment of conditional operator result

Simplified program as follows struct S { S() {} S(const S &) {} S(S &&) = delete; }; S x; S y = false ? S() : x; is accepted just fine by GCC and Clang, but the latest Visual ...
Fedor's user avatar
  • 19.4k
1 vote
1 answer
52 views

Why is it saving the whole mongodb clause not the timestamp?

When I am running it it's saving this whole clause “$cond”: bson.M{ “if”: bson.M{“$eq”: bson.A{“$date”, nil}}, “then”: time.Now(), “else”: “$date”, }, in the document. ...
Napster's user avatar
  • 11
2 votes
2 answers
83 views

On this Conditional Expression, what the syntax error about?

I get: return r.group() if r := re.match(rx,l) else None ^ SyntaxError: invalid syntax whereas return r.group() if (r := re.match(rx,l)) else None is accepted. What ...
ChrisJJ's user avatar
  • 2,238
0 votes
1 answer
46 views

Inserting Javascript array elements into another array with ternary operator

I have an array of objects where each object defines a field in a React form. I want to display different sequence of fields depending on a boolean state. This means that I need to insert either one ...
VikSil's user avatar
  • 98
0 votes
1 answer
38 views

How to use ternary operator for function calls and button text in vuetify vue js 3?

I'm trying to have login button which toggles between icons "loginIcon/logoutIcon", tooltip toggles between Login/Logout and also the corresponding function onclick changes to login/logout. ...
Divya Bharathi's user avatar
0 votes
1 answer
21 views

Conditional rendering not working for flutter widgets

Inside the build method 👇🏽 Widget build(BuildContext context) { final provider = Provider.of<StateProvider>(context, listen: false); // Get the selected question details from the ...
Dumindu Jayasekara's user avatar
0 votes
2 answers
45 views

Understanding the use of bitwise-operator in ternary-operator

I'm just learning how to code and while studying sorting algorithms I was asked to "see if you can combine the two lines in your if and else blocks into one line to make your code look a little ...
Sergio Ruiz Sánchez's user avatar
0 votes
0 answers
36 views

Cannot apply condition to grep output in bash script [duplicate]

The data for this script comes from curl and then I grep a few specific response headers. For this example let's focus on "cf-cache-status". This header has 4 potential values (EXPIRED, HIT, ...
Jeff S's user avatar
  • 109

15 30 50 per page
1
2 3 4 5
134