Add example of Ternary Operator (#25553)
This commit is contained in:
@ -34,6 +34,8 @@ The above statement equal to the statement below
|
|||||||
```
|
```
|
||||||
## Ternary Statement
|
## Ternary Statement
|
||||||
A ternary statement is used as a short conditional statement. It is written as follows
|
A ternary statement is used as a short conditional statement. It is written as follows
|
||||||
|
|
||||||
|
*variable = condition ? true_result : false_result*
|
||||||
* ```ruby
|
* ```ruby
|
||||||
game = "won"
|
game = "won"
|
||||||
fans = game == "won" ? "happy" : unhappy
|
fans = game == "won" ? "happy" : unhappy
|
||||||
@ -52,4 +54,4 @@ A case statement is similar to an if/elsif/else statement
|
|||||||
else
|
else
|
||||||
puts "This is not an apple or an orange"
|
puts "This is not an apple or an orange"
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
Reference in New Issue
Block a user