LoginSignup
0
0

More than 3 years have passed since last update.

初心者向けunlessの使い方

Last updated at Posted at 2021-02-01
1 / 2

今日はunlessの使い方を学習しました。
使い方はifの全く逆です。


if a + b > 0
  puts = "0より大きいです"
end

これと同じ処理をunlessメソッドを使って処理します。


unless a + b <= 0
  puts = "0より大きいです"
end

ここで気をつけて欲しいのは"<"ではなく"<="を使用することです。
"<"を利用すると0も含まれるので"<="としましょう。

0
0
4

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
0
0