Answers for "short if else"

1

java shortest if else statement

(myNumber == 12) ? "true" : "false"
Posted by: Guest on May-21-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
0

if and else shorthand

//Long version  
let points = 70;   
let result;   
if(marks >= 50){  
    result = 'Pass';   
}else{  
    result = 'Fail';   
}

//Shorthand  
let points = 70;   
let result = marks >= 50 ? 'Pass' : 'Fail';
Posted by: Guest on April-27-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language