【読者限定】テックキャンプの割引情報はこちら

【保存版】Rubyの繰り返し処理まとめ

Rubyには繰り返し処理というものがあります。

同じ処理を何度も自動で繰り返すことができる処理ですね。なんか「プログラミング」っぽくなってきましたね。

今回紹介するのは以下です。

Rubyの繰り返し処理

  • timesメソッド
  • eachメソッド
  • for文
  • while文
  • until文
  • loopメソッド

上記の通りです。
それでは順に解説していきます。

timesメソッド

一定の数値を繰り返す処理が実行できる

5.times do |i|
  puts "こんにちは"
end

実行結果

こんにちは
こんにちは
こんにちは
こんにちは
こんにちは

do〜endの中の定義を繰り返します。

eachメソッド

fruits = ["りんご","みかん","ぶどう"]
fruits.each do |fruit|
  puts fruit
end

実行結果

りんご
みかん
ぶどう

このように値を順番に取り出してくれます。

17,215 COMMENTS

canadian pharmacy

Somebody necessarily assist to make critically posts I’d state.
That is the very first time I frequented your web page and to this point?
I surprised with the research you made to make this actual publish extraordinary.
Fantastic task!

返信する
cialis from canada

I am not sure where you’re getting your information, but
good topic. I needs to spend some time learning much more or
understanding more. Thanks for magnificent information I was looking for this information for my mission.

返信する
https://sites.google.com/view/best-ai-content-writing-tools/home

Did you write the article yourself or you hired someone to do it?
I was wondering because I am a site owner too and struggle with writing
new content all the time. Someone told me to use AI to do
create articles which I am kinda considering because the output is almost written by human.
Here is the sample content they sent me – https://sites.google.com/view/best-ai-content-writing-tools/home

Let me know if you think I should go ahead and use AI.

返信する
RaymondHaw

Hello there, I discovered your web site by the use of Google even as searching for a similar topic, your web site got here up, it appears to be like great. I have bookmarked it in my google bookmarks.
Hi there, simply changed into aware of your blog thru Google, and located that it’s truly informative. I’m going to watch out for brussels. I’ll be grateful should you continue this in future. A lot of folks can be benefited out of your writing. Cheers!
essaywritingservicebbc.com

返信する
write my essay for me

An intriguing discussion is definitely worth comment. I
think that you ought to write more about this topic, it might
not be a taboo matter but usually people don’t talk about
these issues. To the next! Cheers!!

返信する
researchpaperwriterservices.com

Can I simply just say what a comfort to uncover someone who truly
understands what they’re discussing on the web.
You definitely understand how to bring a problem to light and make it important.
More people ought to read this and understand this
side of your story. I was surprised you’re not more popular since you
certainly possess the gift.

返信する
helpmedomyxyzhomework.com

Hello there, I think your site could be having browser compatibility problems.
When I take a look at your site in Safari, it looks fine
however, when opening in I.E., it has some overlapping issues.
I simply wanted to give you a quick heads up! Besides that,
great site!

返信する
writeadissertation.com

You actually make it seem so easy with your presentation but I find this topic to
be actually something which I think I would never understand.
It seems too complicated and extremely broad for me. I am looking forward for your next post, I will try
to get the hang of it!

返信する
totosite

It’s the same topic , but I was quite surprised to see the opinions I didn’t think of. My blog also has articles on these topics, so I look forward to your visit. totosite

返信する