タイトル: for文
SEOタイトル: PHP の for 文の使い方とサンプル
この本文には実行可能なタグ等が含まれるため、安全のためHTMLソースとして表示しています。本文データは変更していません。
<p><strong><span style="color:#f39c12"><span style="font-size:16px"><u>for文</u></span></span></strong></p>
<p> </p>
<p><strong><span style="color:#16a085">初期値:</span></strong>処理の始めの値。</p>
<p><strong><span style="color:#2980b9">条件式:</span></strong>繰り返し処理を行うかどうかの判断を行う。</p>
<p><strong><span style="color:#d35400">増減式:</span></strong>処理ごとに値を増減したりなど更新を行う。</p>
<table border="1" cellpadding="1" cellspacing="1" style="width:200px">
<tbody>
<tr>
<td style="background-color:#eeeeee">
<p><strong><span style="font-size:14px">for (<span style="color:#16a085">初期値</span>; <span style="color:#2980b9">条件式;</span> <span style="color:#d35400">増減式</span>) {<br />
繰り返し処理;<br />
}</span></strong></p>
</td>
</tr>
</tbody>
</table>
<p> </p>
<p> </p>
<p><strong>実際にプログラムには以下のように記載する。</strong></p>
<table border="1" cellpadding="1" cellspacing="1" style="width:300px">
<tbody>
<tr>
<td style="background-color:#eeeeee">
<p><strong><span style="font-size:14px"><script><br />
for (<span style="color:#16a085">var i = 0</span>;<span style="color:#2980b9"> i < 5</span>;<span style="color:#d35400"> i++</span>) {<br />
document.write (i);<br />
}<br />
</script></span></strong></p>
</td>
</tr>
</tbody>
</table>
<ol>
<li><span style="font-size:14px"><strong><span style="color:#16a085">初期値</span></strong>「変数iに0」、<strong><span style="color:#2980b9">条件式</span></strong>「iが5未満」、<strong><span style="color:#d35400">増減式</span></strong>「i=i+1」(iに1足したものをiへ格納)を設定。</span></li>
<li><span style="font-size:14px">条件「iが5未満」の間は処理を繰り返し実行。</span></li>
<li><span style="font-size:14px">iが5になると条件からはずれるので、処理がストップされ、ブロックを抜ける。</span></li>
</ol>