1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

条件分岐の処理をifを使って記述できるようになる

Last updated at Posted at 2023-11-17

if の基本の使い方

if の基本的な書き方は以下の通りです。

if "条件"
"条件が正しかった場合の処理"
else
"条件が正しくなかった場合の処理"
end

if gets.to_i >= 100
  puts "Hi"
else
  puts "Low"
end

.to_i とは

文字列オブジェクトを数値オブジェクトに変換するメソッドです。
gets メソッドの戻り値は文字列です。戻り値を数値で処理したい場合は、gets.to_i と記述します。

1
1
1

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?