1
0

More than 3 years have passed since last update.

三項演算子 ❏Ruby❏

Last updated at Posted at 2019-11-18

複数行のif文を一行で書くことができるすぐれもの。

(条件式) ? (trueの場合の処理):(falseの場合の処理)


例)

if score > 60
  puts "合格"
else
  puts "不合格"
end

このif文が

puts score > 60 ? "合格":"不合格"

こうなる。



ではまた!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0