<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>CFLOOP: インデックスループ</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="説明">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">CFLOOP: インデックスループ</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">説明</span>
<p>
インデックスループは、数値で指定された回数だけ繰り返されます。インデックスループは FOR ループとも呼ばれます。 
</p>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="syntax"><span class="title">シンタックス</span><pre>&lt;cfloop
   index = &quot;parameter_name&quot;
   from = &quot;beginning_value&quot;
   to = &quot;ending_value&quot;
   step = &quot;increment&quot;&gt;
   ... HTML または CFML コード ...
&lt;/cfloop&gt;
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">関連項目</span>
<p>
cfabort、cfbreak、cfdirectory、cfexecute、cfexit、cfif、cflocation、cfrethrow、cfswitch、cfthrow、cftry、『ColdFusion MX 開発ガイド』の第2章の「CFML の要素」 の「cfloop と cfbreak」
</p>

<p>

</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">使用方法</span>
<p>
インデックスループの from 属性と to 属性に整数値以外の値を指定すると、予期せぬ結果になる可能性があります。たとえば、インデックスループを通じて 1 ～ 2 の間で 0.1 ずつ加算していく場合、ColdFusion は &quot;1、1.1、1.2、...、1.9&quot; まで出力しますが、&quot;2&quot; は出力しません。これは、浮動小数点数の内部表現に関するプログラミング言語の問題です。 
</p>
<table>
  <tr valign="top">
    <td width="30"><strong>メモ: </strong></td>
    <td>to 値は、cfloop タグが検出されたときに一度だけ評価されます。ループブロック内、またはこの値を評価する式内でこの値を変更しても、ループが実行される回数に影響はありません。 </td>
  </tr>
</table>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">例</span>
<p>
次の例では、ループが 5 回行われ、そのたびに index 値が表示されます。
</p>
<pre>&lt;cfloop index = &quot;LoopCount&quot; from = &quot;1&quot; to = &quot;5&quot;&gt;
   ループインデックスは &lt;cfoutput&gt;#LoopCount#&lt;/cfoutput&gt; です。&lt;br&gt;
&lt;/cfloop&gt;
</pre>
<p>
このループの出力は次のとおりです。 
</p>
<pre>ループインデックスは 1 です。
ループインデックスは 2 です。
ループインデックスは 3 です。
ループインデックスは 4 です。
ループインデックスは 5 です。
</pre>
<p>
次の例では、ループが 4 回行われ、そのたびに index 値が表示されます。j の値はループが繰り返されるたびに減算されます。to の値はループに入る前に j からコピーされたものなので、この減算の影響を受けません。
</p>
<pre>&lt;cfset j = 4&gt;
&lt;cfloop index = &quot;LoopCount&quot; from = &quot;1&quot; to = #j#&gt;
   &lt;cfoutput&gt;ループインデックスは #LoopCount#&lt;/cfoutput&gt;.&lt;br&gt;です。
   &lt;cfset j = j - 1&gt;
&lt;/cfloop&gt;
</pre>
<p>
このループの出力は次のとおりです。 
</p>
<pre>ループインデックスは 1 です。
ループインデックスは 2 です。
ループインデックスは 3 です。
ループインデックスは 4 です。
</pre>
<p>
前述のように、j の値はループが繰り返されるたびに減算されますが、to 値は j がループに入る前に作成されたコピーであるため影響はありません。
</p>

<p>
この例では、step にはデフォルト値 1 が使用されています。次のコードでは、インデックス値が減算されます。
</p>
<pre>&lt;cfloop index = &quot;LoopCount&quot;
   from = &quot;5&quot;
   to = &quot;1&quot;
   step = &quot;-1&quot;&gt;
ループインデックスは &lt;cfoutput&gt;#LoopCount#&lt;/cfoutput&gt;です。&lt;br&gt;
&lt;/cfloop&gt;
</pre>
<p>
このループの出力は次のとおりです。 
</p>
<pre>ループインデックスは 5 です。
ループインデックスは 4 です。
ループインデックスは 3 です。
ループインデックスは 2 です。
ループインデックスは 1 です。
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="INDEX">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">INDEX</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">必須</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>インデックスの値です。この値は最初 from 属性の値に設定され、step 属性の値ずつ、to 属性の値まで加算または減算されます。</p>

  </td>
  </tr>
  </table>
</div>
<div id="FROM">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">FROM</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">必須</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>インデックスの開始値です。</p>

  </td>
  </tr>
  </table>
</div>
<div id="TO">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">TO</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">必須</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">



<p>インデックスの終了値です。</p>

  </td>
  </tr>
  </table>
</div>
<div id="STEP">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">STEP</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>

  <tr>
  <td valign="top" class="syntax">&nbsp;</td>
  <td valign="top" nowrap class="requirements">オプション</td>
  </tr>
  <tr>
  <td colspan="2" class="clearseparation">&nbsp;</td>
  </tr>
  <tr>
  <td valign="top" colspan="2" class="description">

<strong>Default value:</strong> "1"


<p>インデックス値を加算または減算する数値です。</p>

  </td>
  </tr>
  </table>
</div>

  </body>
</html>
