0
1

More than 5 years have passed since last update.

while文とfor文の違い

Posted at

while文やuntil文

「while」文や「until」文は指定した条件式によって繰り返しを継続するかどうかを判断している

ex)num = 0
while num < 100 do
puts num
num += 1
end

for文は?

「for」文ではあらかじめ指定したオブジェクトから順に値を取り出しながら繰り返しを行います。

image.png

ex)for num in 0..99 do
puts num
end

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