LoginSignup
0
0

More than 1 year has passed since last update.

Ruby 入門 [比較メソッド]

Posted at

比較メソッドはその左右にあるものを比較して条件を満たせばtrue、満たさなければfalseを返す。

●if文

If 条件
 条件を満たした時の処理
elsif 条件→※何個でも追加できる
 条件を満たした時の処理
els
    条件を満たさなかった時の処理
end

● || 『または』

if 条件 1 || 条件2
 条件を満たした時の処理
end
 || は、「または」という意味

● && 『かつ』

If 条件1 && 条件2
 条件を満たした時の処理
end

● case

case 変数
when 候補1
 変数の値が1と等しい時の処置(複数行書くこともできる)
when 候補2
 変数の値が2と等しい時の処置(複数行書くこともできる)
(以下、候補をさらに追加できる)
end

● n.times do ● n.times{}

n(回数).times do
 繰り返し実行する処置
end
※複数行の時do end を使う

n(回数).times {
 繰り返し実行する処置
}
※一行の時は{}を使う

● while

while 条件
 条件を満たしている間、繰り返し実行する処理
end
0
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
0
0