You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
942 B
55 lines
942 B
4 years ago
|
pragma solidity ^0.7.0;
|
||
|
|
||
|
|
||
|
contract Contract_ternary {
|
||
|
|
||
|
// Sameline consequent
|
||
|
function a() public {
|
||
|
bool x = true;
|
||
|
bool y = true;
|
||
|
x && y ? y = false : y = false;
|
||
|
}
|
||
|
|
||
|
// Multiline consequent
|
||
|
function b() public {
|
||
|
bool x = false;
|
||
|
bool y = false;
|
||
|
(x)
|
||
|
? y = false
|
||
|
: y = false;
|
||
|
}
|
||
|
|
||
|
// Sameline w/ logicalOR
|
||
|
function c() public {
|
||
|
bool x = false;
|
||
|
bool y = true;
|
||
|
(x || y) ? y = false : y = false;
|
||
|
}
|
||
|
|
||
|
// Multiline w/ logicalOR
|
||
|
function d() public {
|
||
|
bool x = false;
|
||
|
bool y = true;
|
||
|
(x || y)
|
||
|
? y = false
|
||
|
: y = false;
|
||
|
}
|
||
|
|
||
|
// Sameline alternate
|
||
|
function e() public {
|
||
|
bool x = false;
|
||
|
bool y = false;
|
||
|
(x) ? y = false : y = false;
|
||
|
}
|
||
|
|
||
|
// Multiline w/ logicalOR (both false)
|
||
|
function f() public {
|
||
|
bool x = false;
|
||
|
bool y = false;
|
||
|
(x || y)
|
||
|
? y = false
|
||
|
: y = false;
|
||
|
}
|
||
|
|
||
|
}
|