1
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 5 years have passed since last update.

繰り返し処理 ブロック〜Udemy〜

1
Posted at

繰り返し処理

・Rubyで特徴的なのはブロックという、”処理のカタマリ”を渡すことができる仕組みがある


ブロック

・[式] do |I|        # Iはブロックパラメーター
       処理
   end

ある式があって、一つづつパラメーターを追加しながら処理をしていく
例えば1〜20までの数を表示するとか、もしくは20からカウントダウンして、0まで表示する。
2づつ減らして表示するなどの、繰り返し処理をブロックとして記述するなどの方法がある

・2番目によく使うとされるのが、

Until f.eof       ➡️ end of fileの略:ファイルの終端
   Print f.gets   ➡️getsメソッド ファイルから一行ぶんデータを読み込む
end

ファイルの読み込み処理
データサイエンス・統計処理などでよく使用する

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