{"id":80078,"date":"2024-03-29T09:08:31","date_gmt":"2024-03-29T00:08:31","guid":{"rendered":"https://freelance.indieverse.co.jp/media/?p=80078"},"modified":"2026-06-08T16:08:41","modified_gmt":"2026-06-08T07:08:41","slug":"ruby-for","status":"publish","type":"post","link":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for","title":{"rendered":"【Ruby】for文の使い方を初心者向けに解説 | eachとの違いについても理解しよう"},"content":{"rendered":"<p>この記事では、</p>\n<ul>\n<li><strong>for文の基本文法とその使用方法</strong></li>\n<li><strong>for文とeachメソッドの違いとそれぞれの利用シーン</strong></li>\n<li><strong>for文を使った具体的な実例とそれらの解説</strong></li>\n</ul>\n<p>について解説していきたいと思います。</p>\n<h2>for文とは</h2>\n<p>Rubyにおける<code>for</code>文は、指定した条件に従って、一連のコードを繰り返し実行するために使用される制御構造です。基本的な構文は以下のようになります。</p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>for 変数 in 範囲または配列 do\r\n   # 実行したいコード\r\nend</code></pre>\n</div>\n<p>例えば、1から5までの数字を出力したい場合は以下のように記述します。</p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>for num in 1..5 do\r\n   puts num\r\nend</code></pre>\n</div>\n<p>実行結果:</p>\n<p><code></code></p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>1\r\n2\r\n3\r\n4\r\n5</code></pre>\n</div>\n<p>&nbsp;</p>\n<p>このように、<code>for</code>文を使って特定の回数や範囲に沿って処理を繰り返すことができます。</p>\n<h2>for文とeachの違い</h2>\n<p><code>for</code>文と<code>each</code>メソッドは共に繰り返し処理を行うものですが、その使い方にはいくつか違いがあります。</p>\n<p><code>for</code>文は比較的シンプルで直感的な文法を持っている一方、<code>each</code>メソッドはブロックを使用し、よりRubyらしい書き方とされています。</p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code># for文の例\r\nfor num in 1..5 do\r\n   puts num\r\nend\r\n\r\n# eachメソッドの例\r\n\r\n(1..5).each do |num|\r\n   puts num\r\nend</code></pre>\n</div>\n<p>両者の実行結果は同じですが、<code>each</code>ではブロック変数（<code>|num|</code>の部分）を使用して、範囲の各要素を参照しています。</p>\n<p>このように<code>each</code>メソッドの方がRubyのイディオムに沿った記述が可能です。</p>\n<div class='balloon5'>\n<div class='faceicon'>\n\t\t\t<img src='https://pbs.twimg.com/profile_images/1230103371664613376/PHLMWlPU_400x400.jpg'></p>\n<div style='text-align:center'>DAI</div>\n</p></div>\n<div class='chatting'>\n<div class='says'>実際のRubyやRuby on Railsのプロジェクトにいると、ほとんどfor inは見ない印象があります。どちらかというとeachを利用するケースが多いです。</div>\n</p></div>\n</p></div>\n<p>参考：<a href=\"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-each\">【Ruby】eachメソッドの使い方の基礎から応用まで現役エンジニアが解説します</a></p>\n<p><a href=\"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-each\" target=\"_blank\" rel=\"noopener\"></a></p>\n<h3>each文と比べたfor文のメリットと使い道</h3>\n<p><code>for</code>文のメリットはそのシンプルさにあります。特に、他のプログラミング言語からRubyに移行してきた人にとっては、<code>for</code>文の方が理解しやすい場合があります。</p>\n<div class='balloon5'>\n<div class='faceicon'>\n\t\t\t<img src='https://pbs.twimg.com/profile_images/1230103371664613376/PHLMWlPU_400x400.jpg'></p>\n<div style='text-align:center'>DAI</div>\n</p></div>\n<div class='chatting'>\n<div class='says'>特にPythonから来た人にとっては、for in構文は馴染み深いかと思います</div>\n</p></div>\n</p></div>\n<p>一方で、Rubyのコミュニティでは<code>each</code>メソッドを用いることが推奨されているため、Rubyのスタイルに慣れるためには<code>each</code>メソッドを使いこなせるようになることが重要です。</p>\n<h3>For文で範囲指定や複数条件でのループ</h3>\n<p><code>for</code>文は、単純な範囲指定だけでなく、複数の条件でのループ実行にも応用可能です。たとえば、配列の要素をループ処理する場合、以下のように記述できます。</p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>fruits = [\"りんご\", \"みかん\", \"バナナ\", \"メロン\"]\r\nfor fruit in fruits do\r\n   puts fruit\r\nend</code></pre>\n</div>\n<p>実行結果:</p>\n<p><code></code></p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>りんご\r\nみかん\r\nバナナ\r\nメロン</code></pre>\n</div>\n<p>&nbsp;</p>\n<p>この例のように配列の要素に順番にアクセスしてその内容を出力することができます。</p>\n<p><code>for</code>文は範囲だけでなく配列やハッシュの要素に対しても使用できるため、データ構造に応じた繰り返し処理を行うことが可能です。</p>\n<h3>データ構造を活用した繰り返し</h3>\n<p>また、<code>for</code>文はハッシュの要素に対しても使うことができます。キーと値のペアを順番に取り出して何らかの処理を行う場合には、以下のように記述します。<code></code></p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>scores = {\"数学\" =&gt; 80, \"英語\" =&gt; 75, \"科学\" =&gt; 90}\r\nfor subject, score in scores do\r\n   puts \"#{subject}: #{score}点\"\r\nend</code></pre>\n</div>\n<p>実行結果:</p>\n<p><code></code></p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>数学: 80点\r\n\r\n英語: 75点\r\n\r\n科学: 90点</code></pre>\n</div>\n<p>このように、<code>for</code>文を使ってハッシュの各要素にアクセスし、キーと値のペアを利用した繰り返し処理が実現できます。この柔軟性により、<code>for</code>文は多様なデータ構造に対応する強力なツールとなります。</p>\n<h2>for文でのループ制御</h2>\n<h3>スキップや再試行、脱出の条件設定</h3>\n<p><code>for</code>文内で繰り返し処理をより細かく制御するためには、<code>next</code>、<code>redo</code>、<code>break</code>などのキーワードを使用します。例えば、特定の条件で処理をスキップしたい場合は<code>next</code>を使います。</p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>for i in 1..5 do\r\n   next if i % 2 == 0 # iが偶数の場合は次の繰り返しにスキップ\r\n\r\n   puts i\r\nend</code></pre>\n</div>\n<p>実行結果:</p>\n<p><code></code></p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>1\r\n\r\n3\r\n\r\n5</code></pre>\n</div>\n<p>&nbsp;</p>\n<p>このコードでは、<code>i</code>が偶数の場合、<code>puts i</code>の処理をスキップし、奇数のみが出力されます。</p>\n<p>このように<code>for</code>文では、<code>next</code>、<code>redo</code>、<code>break</code>を使ってループの流れをコントロールすることができます。</p>\n<h2>for文の注意点</h2>\n<h3>for文の構文と動作の流れ</h3>\n<p><code>for</code>文を使用する際にはその構文と動作の流れを正確に理解しておきましょう。</p>\n<p>特に、無限ループに陥らないように、ループの終了条件を明確にすることが重要です。</p>\n<p>また、<code>for</code>文にはブロック変数がスコープ外でアクセスできるという特徴がありますが、これによって予期しない変数の上書きが発生する可能性があるため注意が必要です。</p>\n<h3>変数のスコープと無限ループの回避</h3>\n<p>Rubyの<code>for</code>文では、ループ内で宣言された変数がループ外でも利用可能という特徴があります。これは便利な一方で、不意の変数の上書きにつながる可能性もあるため、変数の命名には注意が必要です。また、繰り返し処理を設計する際には、終了条件を適切に設定し、無限ループにならないようにすることが肝心です。</p>\n<p>この記事を通じて、Rubyの<code>for</code>文についての基本的な理解を深めることができたでしょう。さまざまな場面で<code>for</code>文を効果的に使いこなし、Rubyプログラミングのスキルを高めていきましょう。</p>\n<h2>for文以外の繰り返し（iteration)</h2>\n<h3>while文</h3>\n<p>Rubyでは<code>for</code>文の他にも、<code>while</code>文を使って繰り返し処理を行うことができます。<code>while</code>文は、指定された条件が真（true）である限り繰り返し実行されます。条件が偽（false）になるまでループが続きます。</p>\n<p><code>ruby</code></p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>i = 1\r\nwhile i &lt;= 5 do\r\n   puts i\r\n   i += 1\r\nend</code></pre>\n</div>\n<p>実行結果:</p>\n<p><code></code></p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>1\r\n\r\n2\r\n\r\n3\r\n\r\n4\r\n\r\n5</code></pre>\n</div>\n<h3>unless文</h3>\n<p>Rubyにおいて<code>unless</code>文は、ある条件が偽である場合にのみ、指定された処理を実行する構文です。ただし、直接的な繰り返し処理には使用されません。</p>\n<h3>each文</h3>\n<p>Rubyのイディオムとして多用される<code>each</code>メソッドは、配列やハッシュなどのコレクションの各要素に対して繰り返し処理を行います。</p>\n<p><code>each</code>メソッドを使ったコードは、よりRubyらしいコードとして推奨されます。</p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>[1, 2, 3, 4, 5].each do |i|\r\n   puts i\r\nend</code></pre>\n</div>\n<p>&nbsp;</p>\n<p>実行結果:</p>\n<p><code></code></p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-ruby\" data-lang=\"Ruby\"><code>1\r\n\r\n2\r\n\r\n3\r\n\r\n4\r\n\r\n5</code></pre>\n</div>\n<p><code>for</code>文、<code>while</code>文、<code>each</code>メソッドなど、Rubyにおいて繰り返し処理を行う方法は様々です。目的や好みに応じて最適な方法を選びましょう。</p>\n<h2>Rubyの繰り返し処理をRails案件で活かすには</h2>\n<p>Ruby on Railsの実務では、<code>for</code>文よりも<code>each</code>や<code>map</code>などのメソッドを使う場面が多くあります。ただし、<code>for</code>文を理解しておくと、繰り返し処理の仕組みや他の書き方との違いを整理しやすくなります。</p>\n<p>Rails案件で求められるRubyの書き方や開発範囲を知りたい方は、<a href=\"https://freelance.indieverse.co.jp/job_listings/skills/389\">Ruby on Rails案件一覧</a>で、募集要件に出てくる実装内容を確認してみましょう。</p>\n","protected":false},"excerpt":{"rendered":"<p>Rubyのfor文の基本文法と使い方を初心者向けに解説。eachとの違いと使い分け、配列・ハッシュ操作、nextやbreakなどのループ制御、スコープの注意点まで網羅します。</p>\n","protected":false},"author":1,"featured_media":80039,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[190],"tags":[286],"class_list":["post-80078","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby","tag-ruby"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.3 - aioseo.com -->\n\t<meta name=\"description\" content=\"Rubyのfor文の基本文法と使い方を初心者向けに解説。eachとの違いと使い分け、配列・ハッシュ操作、nextやbreakなどのループ制御、スコープの注意点まで網羅します。\" />\n\t<meta name=\"robots\" content=\"max-image-preview:large\" />\n\t<meta name=\"author\" content=\"DAI\"/>\n\t<link rel=\"canonical\" href=\"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for\" />\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.3\" />\n\t\t<meta property=\"og:locale\" content=\"ja_JP\" />\n\t\t<meta property=\"og:site_name\" content=\"インディバースフリーランスメディア - Indieverse Freelanceの公式メディアです\" />\n\t\t<meta property=\"og:type\" content=\"article\" />\n\t\t<meta property=\"og:title\" content=\"【Ruby】for文の使い方を初心者向けに解説 | eachとの違いについても理解しよう - インディバースフリーランスメディア\" />\n\t\t<meta property=\"og:description\" content=\"Rubyのfor文の基本文法と使い方を初心者向けに解説。eachとの違いと使い分け、配列・ハッシュ操作、nextやbreakなどのループ制御、スコープの注意点まで網羅します。\" />\n\t\t<meta property=\"og:url\" content=\"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for\" />\n\t\t<meta property=\"article:published_time\" content=\"2024-03-29T00:08:31+00:00\" />\n\t\t<meta property=\"article:modified_time\" content=\"2026-06-08T07:08:41+00:00\" />\n\t\t<meta name=\"twitter:card\" content=\"summary\" />\n\t\t<meta name=\"twitter:title\" content=\"【Ruby】for文の使い方を初心者向けに解説 | eachとの違いについても理解しよう - インディバースフリーランスメディア\" />\n\t\t<meta name=\"twitter:description\" content=\"Rubyのfor文の基本文法と使い方を初心者向けに解説。eachとの違いと使い分け、配列・ハッシュ操作、nextやbreakなどのループ制御、スコープの注意点まで網羅します。\" />\n\t\t<script type=\"application/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\/\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/programming\\/ruby\\/ruby-for#blogposting\",\"name\":\"\\u3010Ruby\\u3011for\\u6587\\u306e\\u4f7f\\u3044\\u65b9\\u3092\\u521d\\u5fc3\\u8005\\u5411\\u3051\\u306b\\u89e3\\u8aac | each\\u3068\\u306e\\u9055\\u3044\\u306b\\u3064\\u3044\\u3066\\u3082\\u7406\\u89e3\\u3057\\u3088\\u3046 - \\u30a4\\u30f3\\u30c7\\u30a3\\u30d0\\u30fc\\u30b9\\u30d5\\u30ea\\u30fc\\u30e9\\u30f3\\u30b9\\u30e1\\u30c7\\u30a3\\u30a2\",\"headline\":\"\\u3010Ruby\\u3011for\\u6587\\u306e\\u4f7f\\u3044\\u65b9\\u3092\\u521d\\u5fc3\\u8005\\u5411\\u3051\\u306b\\u89e3\\u8aac | each\\u3068\\u306e\\u9055\\u3044\\u306b\\u3064\\u3044\\u3066\\u3082\\u7406\\u89e3\\u3057\\u3088\\u3046\",\"author\":{\"@id\":\"https:\\/\\/freelance.dividable.net\\/author\\/wpmaster#author\"},\"publisher\":{\"@id\":\"https:\\/\\/freelance.dividable.net\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\/\\/freelance.dividable.net\\/wp-content\\/uploads\\/2024\\/03\\/AdobeStock_416662619-scaled.jpeg\",\"width\":2560,\"height\":1707},\"datePublished\":\"2024-03-29T09:08:31+09:00\",\"dateModified\":\"2026-06-08T16:08:41+09:00\",\"inLanguage\":\"ja\",\"mainEntityOfPage\":{\"@id\":\"https:\\/\\/freelance.dividable.net\\/programming\\/ruby\\/ruby-for#webpage\"},\"isPartOf\":{\"@id\":\"https:\\/\\/freelance.dividable.net\\/programming\\/ruby\\/ruby-for#webpage\"},\"articleSection\":\"Ruby, Ruby\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/programming\\/ruby\\/ruby-for#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/#listItem\",\"position\":1,\"name\":\"\\u30db\\u30fc\\u30e0\",\"item\":\"https:\\/\\/freelance.dividable.net\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/category\\/programming#listItem\",\"name\":\"\\u30d7\\u30ed\\u30b0\\u30e9\\u30df\\u30f3\\u30b0\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/category\\/programming#listItem\",\"position\":2,\"name\":\"\\u30d7\\u30ed\\u30b0\\u30e9\\u30df\\u30f3\\u30b0\",\"item\":\"https:\\/\\/freelance.dividable.net\\/category\\/programming\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/category\\/programming\\/ruby#listItem\",\"name\":\"Ruby\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/#listItem\",\"name\":\"\\u30db\\u30fc\\u30e0\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/category\\/programming\\/ruby#listItem\",\"position\":3,\"name\":\"Ruby\",\"item\":\"https:\\/\\/freelance.dividable.net\\/category\\/programming\\/ruby\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/programming\\/ruby\\/ruby-for#listItem\",\"name\":\"\\u3010Ruby\\u3011for\\u6587\\u306e\\u4f7f\\u3044\\u65b9\\u3092\\u521d\\u5fc3\\u8005\\u5411\\u3051\\u306b\\u89e3\\u8aac | each\\u3068\\u306e\\u9055\\u3044\\u306b\\u3064\\u3044\\u3066\\u3082\\u7406\\u89e3\\u3057\\u3088\\u3046\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/category\\/programming#listItem\",\"name\":\"\\u30d7\\u30ed\\u30b0\\u30e9\\u30df\\u30f3\\u30b0\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/programming\\/ruby\\/ruby-for#listItem\",\"position\":4,\"name\":\"\\u3010Ruby\\u3011for\\u6587\\u306e\\u4f7f\\u3044\\u65b9\\u3092\\u521d\\u5fc3\\u8005\\u5411\\u3051\\u306b\\u89e3\\u8aac | each\\u3068\\u306e\\u9055\\u3044\\u306b\\u3064\\u3044\\u3066\\u3082\\u7406\\u89e3\\u3057\\u3088\\u3046\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/category\\/programming\\/ruby#listItem\",\"name\":\"Ruby\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/#organization\",\"name\":\"Indieverse Freelance\",\"description\":\"Indieverse Freelance\\u306e\\u516c\\u5f0f\\u30e1\\u30c7\\u30a3\\u30a2\\u3067\\u3059\",\"url\":\"https:\\/\\/freelance.dividable.net\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/author\\/wpmaster#author\",\"url\":\"https:\\/\\/freelance.dividable.net\\/author\\/wpmaster\",\"name\":\"DAI\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/programming\\/ruby\\/ruby-for#webpage\",\"url\":\"https:\\/\\/freelance.dividable.net\\/programming\\/ruby\\/ruby-for\",\"name\":\"\\u3010Ruby\\u3011for\\u6587\\u306e\\u4f7f\\u3044\\u65b9\\u3092\\u521d\\u5fc3\\u8005\\u5411\\u3051\\u306b\\u89e3\\u8aac | each\\u3068\\u306e\\u9055\\u3044\\u306b\\u3064\\u3044\\u3066\\u3082\\u7406\\u89e3\\u3057\\u3088\\u3046 - \\u30a4\\u30f3\\u30c7\\u30a3\\u30d0\\u30fc\\u30b9\\u30d5\\u30ea\\u30fc\\u30e9\\u30f3\\u30b9\\u30e1\\u30c7\\u30a3\\u30a2\",\"description\":\"Ruby\\u306efor\\u6587\\u306e\\u57fa\\u672c\\u6587\\u6cd5\\u3068\\u4f7f\\u3044\\u65b9\\u3092\\u521d\\u5fc3\\u8005\\u5411\\u3051\\u306b\\u89e3\\u8aac\\u3002each\\u3068\\u306e\\u9055\\u3044\\u3068\\u4f7f\\u3044\\u5206\\u3051\\u3001\\u914d\\u5217\\u30fb\\u30cf\\u30c3\\u30b7\\u30e5\\u64cd\\u4f5c\\u3001next\\u3084break\\u306a\\u3069\\u306e\\u30eb\\u30fc\\u30d7\\u5236\\u5fa1\\u3001\\u30b9\\u30b3\\u30fc\\u30d7\\u306e\\u6ce8\\u610f\\u70b9\\u307e\\u3067\\u7db2\\u7f85\\u3057\\u307e\\u3059\\u3002\",\"inLanguage\":\"ja\",\"isPartOf\":{\"@id\":\"https:\\/\\/freelance.dividable.net\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\/\\/freelance.dividable.net\\/programming\\/ruby\\/ruby-for#breadcrumblist\"},\"author\":{\"@id\":\"https:\\/\\/freelance.dividable.net\\/author\\/wpmaster#author\"},\"creator\":{\"@id\":\"https:\\/\\/freelance.dividable.net\\/author\\/wpmaster#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\/\\/freelance.dividable.net\\/wp-content\\/uploads\\/2024\\/03\\/AdobeStock_416662619-scaled.jpeg\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/programming\\/ruby\\/ruby-for\\/#mainImage\",\"width\":2560,\"height\":1707},\"primaryImageOfPage\":{\"@id\":\"https:\\/\\/freelance.dividable.net\\/programming\\/ruby\\/ruby-for#mainImage\"},\"datePublished\":\"2024-03-29T09:08:31+09:00\",\"dateModified\":\"2026-06-08T16:08:41+09:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\/\\/freelance.dividable.net\\/#website\",\"url\":\"https:\\/\\/freelance.dividable.net\\/\",\"name\":\"\\u30a4\\u30f3\\u30c7\\u30a3\\u30d0\\u30fc\\u30b9\\u30d5\\u30ea\\u30fc\\u30e9\\u30f3\\u30b9\\u30e1\\u30c7\\u30a3\\u30a2\",\"description\":\"Indieverse Freelance\\u306e\\u516c\\u5f0f\\u30e1\\u30c7\\u30a3\\u30a2\\u3067\\u3059\",\"inLanguage\":\"ja\",\"publisher\":{\"@id\":\"https:\\/\\/freelance.dividable.net\\/#organization\"}}]}\n\t\t</script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"【Ruby】for文の使い方を初心者向けに解説 | eachとの違いについても理解しよう - インディバースフリーランスメディア","description":"Rubyのfor文の基本文法と使い方を初心者向けに解説。eachとの違いと使い分け、配列・ハッシュ操作、nextやbreakなどのループ制御、スコープの注意点まで網羅します。","canonical_url":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https://schema.org","@graph":[{"@type":"BlogPosting","@id":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for#blogposting","name":"【Ruby】for文の使い方を初心者向けに解説 | eachとの違いについても理解しよう - インディバースフリーランスメディア","headline":"【Ruby】for文の使い方を初心者向けに解説 | eachとの違いについても理解しよう","author":{"@id":"https://freelance.indieverse.co.jp/media/author/wpmaster#author"},"publisher":{"@id":"https://freelance.indieverse.co.jp/media/#organization"},"image":{"@type":"ImageObject","url":"https://freelance.indieverse.co.jp/media/wp-content/uploads/2024/03/AdobeStock_416662619-scaled.jpeg","width":2560,"height":1707},"datePublished":"2024-03-29T09:08:31+09:00","dateModified":"2026-06-08T16:08:41+09:00","inLanguage":"ja","mainEntityOfPage":{"@id":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for#webpage"},"isPartOf":{"@id":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for#webpage"},"articleSection":"Ruby, Ruby"},{"@type":"BreadcrumbList","@id":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https://freelance.indieverse.co.jp/media/#listItem","position":1,"name":"ホーム","item":"https://freelance.indieverse.co.jp/media/","nextItem":{"@type":"ListItem","@id":"https://freelance.indieverse.co.jp/media/category/programming#listItem","name":"プログラミング"}},{"@type":"ListItem","@id":"https://freelance.indieverse.co.jp/media/category/programming#listItem","position":2,"name":"プログラミング","item":"https://freelance.indieverse.co.jp/media/category/programming","nextItem":{"@type":"ListItem","@id":"https://freelance.indieverse.co.jp/media/category/programming/ruby#listItem","name":"Ruby"},"previousItem":{"@type":"ListItem","@id":"https://freelance.indieverse.co.jp/media/#listItem","name":"ホーム"}},{"@type":"ListItem","@id":"https://freelance.indieverse.co.jp/media/category/programming/ruby#listItem","position":3,"name":"Ruby","item":"https://freelance.indieverse.co.jp/media/category/programming/ruby","nextItem":{"@type":"ListItem","@id":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for#listItem","name":"【Ruby】for文の使い方を初心者向けに解説 | eachとの違いについても理解しよう"},"previousItem":{"@type":"ListItem","@id":"https://freelance.indieverse.co.jp/media/category/programming#listItem","name":"プログラミング"}},{"@type":"ListItem","@id":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for#listItem","position":4,"name":"【Ruby】for文の使い方を初心者向けに解説 | eachとの違いについても理解しよう","previousItem":{"@type":"ListItem","@id":"https://freelance.indieverse.co.jp/media/category/programming/ruby#listItem","name":"Ruby"}}]},{"@type":"Organization","@id":"https://freelance.indieverse.co.jp/media/#organization","name":"Indieverse Freelance","description":"Indieverse Freelanceの公式メディアです","url":"https://freelance.indieverse.co.jp/media/"},{"@type":"Person","@id":"https://freelance.indieverse.co.jp/media/author/wpmaster#author","url":"https://freelance.indieverse.co.jp/media/author/wpmaster","name":"DAI"},{"@type":"WebPage","@id":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for#webpage","url":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for","name":"【Ruby】for文の使い方を初心者向けに解説 | eachとの違いについても理解しよう - インディバースフリーランスメディア","description":"Rubyのfor文の基本文法と使い方を初心者向けに解説。eachとの違いと使い分け、配列・ハッシュ操作、nextやbreakなどのループ制御、スコープの注意点まで網羅します。","inLanguage":"ja","isPartOf":{"@id":"https://freelance.indieverse.co.jp/media/#website"},"breadcrumb":{"@id":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for#breadcrumblist"},"author":{"@id":"https://freelance.indieverse.co.jp/media/author/wpmaster#author"},"creator":{"@id":"https://freelance.indieverse.co.jp/media/author/wpmaster#author"},"image":{"@type":"ImageObject","url":"https://freelance.indieverse.co.jp/media/wp-content/uploads/2024/03/AdobeStock_416662619-scaled.jpeg","@id":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for/#mainImage","width":2560,"height":1707},"primaryImageOfPage":{"@id":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for#mainImage"},"datePublished":"2024-03-29T09:08:31+09:00","dateModified":"2026-06-08T16:08:41+09:00"},{"@type":"WebSite","@id":"https://freelance.indieverse.co.jp/media/#website","url":"https://freelance.indieverse.co.jp/media/","name":"インディバースフリーランスメディア","description":"Indieverse Freelanceの公式メディアです","inLanguage":"ja","publisher":{"@id":"https://freelance.indieverse.co.jp/media/#organization"}}]},"og:locale":"ja_JP","og:site_name":"インディバースフリーランスメディア - Indieverse Freelanceの公式メディアです","og:type":"article","og:title":"【Ruby】for文の使い方を初心者向けに解説 | eachとの違いについても理解しよう - インディバースフリーランスメディア","og:description":"Rubyのfor文の基本文法と使い方を初心者向けに解説。eachとの違いと使い分け、配列・ハッシュ操作、nextやbreakなどのループ制御、スコープの注意点まで網羅します。","og:url":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for","article:published_time":"2024-03-29T00:08:31+00:00","article:modified_time":"2026-06-08T07:08:41+00:00","twitter:card":"summary","twitter:title":"【Ruby】for文の使い方を初心者向けに解説 | eachとの違いについても理解しよう - インディバースフリーランスメディア","twitter:description":"Rubyのfor文の基本文法と使い方を初心者向けに解説。eachとの違いと使い分け、配列・ハッシュ操作、nextやbreakなどのループ制御、スコープの注意点まで網羅します。"},"aioseo_meta_data":{"post_id":"80078","title":null,"description":null,"keywords":null,"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"#aioseo-article-67f5c57840f1f","slug":"article","graphName":"Article","label":"記事","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"limit_modified_date":false,"created":"2024-03-28 23:58:42","updated":"2025-09-08 22:47:13","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https://freelance.indieverse.co.jp/media/\" title=\"ホーム\">ホーム</a>\n\t\t</span><span class=\"aioseo-breadcrumb-separator\">»</span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https://freelance.indieverse.co.jp/media/category/programming\" title=\"プログラミング\">プログラミング</a>\n\t\t</span><span class=\"aioseo-breadcrumb-separator\">»</span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https://freelance.indieverse.co.jp/media/category/programming/ruby\" title=\"Ruby\">Ruby</a>\n\t\t</span><span class=\"aioseo-breadcrumb-separator\">»</span><span class=\"aioseo-breadcrumb\">\n\t\t\t【Ruby】for文の使い方を初心者向けに解説 | eachとの違いについても理解しよう\n\t\t</span></div>","aioseo_breadcrumb_json":[{"label":"ホーム","link":"https://freelance.indieverse.co.jp/media/"},{"label":"プログラミング","link":"https://freelance.indieverse.co.jp/media/category/programming"},{"label":"Ruby","link":"https://freelance.indieverse.co.jp/media/category/programming/ruby"},{"label":"【Ruby】for文の使い方を初心者向けに解説 | eachとの違いについても理解しよう","link":"https://freelance.indieverse.co.jp/media/programming/ruby/ruby-for"}],"meta_description":"Rubyのfor文の基本文法と使い方を初心者向けに解説。eachとの違いと使い分け、配列・ハッシュ操作、nextやbreakなどのループ制御、スコープの注意点まで網羅します。","_links":{"self":[{"href":"https://freelance.indieverse.co.jp/media/wp-json/wp/v2/posts/80078","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https://freelance.indieverse.co.jp/media/wp-json/wp/v2/posts"}],"about":[{"href":"https://freelance.indieverse.co.jp/media/wp-json/wp/v2/types/post"}],"author":[{"embeddable":true,"href":"https://freelance.indieverse.co.jp/media/wp-json/wp/v2/users/1"}],"replies":[{"embeddable":true,"href":"https://freelance.indieverse.co.jp/media/wp-json/wp/v2/comments?post=80078"}],"version-history":[{"count":4,"href":"https://freelance.indieverse.co.jp/media/wp-json/wp/v2/posts/80078/revisions"}],"predecessor-version":[{"id":96851,"href":"https://freelance.indieverse.co.jp/media/wp-json/wp/v2/posts/80078/revisions/96851"}],"wp:featuredmedia":[{"embeddable":true,"href":"https://freelance.indieverse.co.jp/media/wp-json/wp/v2/media/80039"}],"wp:attachment":[{"href":"https://freelance.indieverse.co.jp/media/wp-json/wp/v2/media?parent=80078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https://freelance.indieverse.co.jp/media/wp-json/wp/v2/categories?post=80078"},{"taxonomy":"post_tag","embeddable":true,"href":"https://freelance.indieverse.co.jp/media/wp-json/wp/v2/tags?post=80078"}],"curies":[{"name":"wp","href":"https://api.w.org/{rel}","templated":true}]}}