0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ruby 練習問題44 (アウトプット用)

Posted at

times文を使って、以下のようにターミナルに出力されるプログラムを書く問題。

1回目の繰り返し
2回目の繰り返し
3回目の繰り返し
4回目の繰り返し
5回目の繰り返し
6回目の繰り返し
7回目の繰り返し
8回目の繰り返し
9回目の繰り返し
10回目の繰り返し

以下、模範解答

10.times do |i|
  puts "#{i + 1}回目の繰り返し
end

以下、解説
times文を使い、puts "○回目の繰り返し"という処理を繰り返し行う。
今回は○回目の○の部分に数字を1ずつ足していかなければいけないので変数を使用する。(今回は変数iとする。)
プログラムなので、1回目の繰り返しではiは0になるので(i + 1)回目の繰り返しとすれば1となる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?