Answers for "short if"

1

java shortest if else statement

(myNumber == 12) ? "true" : "false"
Posted by: Guest on May-21-2020
15

short if

condition ? doThisIfTrue : doThisIfFalse

1 > 2 ? console.log(true) : console.log(false)
// returns false
Posted by: Guest on May-21-2020
6

c# ternary

// ---------------- Syntax of Ternary Operators ----------------- //

string stateOfMatter;
int temperature = 23;


// ---- For just one condition ---- //
stateOfMatter = temperature < 0 ? "Solid": "Liquid";
  
// If temperature is below zero, then stateOfMatter is solid, otherwise
// it will be liquid
  
  
// ---- For more conditions ---- //
stateOfMatter = temperature < 0 ? "Solid" : (temperature > 100 ? "Gas" : "Liquid");
Posted by: Guest on August-28-2020
1

short for if

#include <iostream>

//Another variation:
    a == 1 ? std::cout << "1" : (a == 2 ? std::cout << "2"  : a = 3);

//This is the same as:
if(a == 1)
{
    std::cout << "1";    
}
else if (a == 2)
{
    std::cout << "2";
}
else
{
    a = 3;
}
Posted by: Guest on February-09-2021
1

c# ternary condition

condition ? consequent : alternative
Posted by: Guest on July-30-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language