You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
Rubyの繰り返し処理についてです。前回条件分岐について書きましたが、この2つは一番よく使うものだと思いますし、これが汚いとコードの可読性も悪くなるので、正確に理解して綺麗なコードを書けるようにしていかないといけないですね。 for文について for文の基本的な構文は次のようになります。doは省略可能です。 for 変数 in オブジェクト do 繰り返す処理 end オブジェクトはなんでも指定できるわけではありません。基本的には配列とかハッシュですね。次の例では配列からひとつずつ要素を取得して変数に渡しています。Javaでいう拡張for文のような感じです。また、変数はfor文の外からでも呼び出せます。 strs = ["a", "b", "c"] for str in strs puts str end #=>a # b # c ハッシュを使う場合は変数をカンマ区切りで2つ指定してあげま
繰り返し処理を行う方法の一つが for 文です。 while 文や until 文は条件式が真か偽かで繰り返しを行いましたが、 for 文では指定したオブジェクトから繰り返しのたびに値を取り出し、値がなくなるまで繰り返しを行います。ここでは Ruby で for 文を使った繰り返し処理を行う方法について解説します。
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く