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.

times文を用いた繰り返し処理問題

Posted at

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

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

自分の答え
10.times do|i| 
  puts "#{(i+1)}回目の繰り返し"
end

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

修正が必要な点
ブロック変数+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?