coldfusion 指数
示例
参数
基本索引循环
最终值为x10。
<!--- Tags --->
<cfoutput>
<cfloop index="x" from="1" to="10">
<li>#x#</li>
</cfloop>
</cfoutput>
<!--- cfscript --->
<cfscript>
for (x = 1; x <= 10; x++) {
writeOutput('<li>' & x & '</li>');
}
</cfscript>
<!--- HTML Output --->
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10增加到2
最终值为x11。
<!--- Tags --->
<cfoutput>
<cfloop index="x" from="1" to="10" step="2">
<li>#x#</li>
</cfloop>
</cfoutput>
<!--- cfscript --->
<cfscript>
for (x = 1; x <= 10; x += 2) {
writeOutput('<li>' & x & '</li>');
}
</cfscript>
<!--- HTML Output --->
- 1
- 3
- 5
- 7
- 9递减1
最终值为x0。
<!--- Tags --->
<cfoutput>
<cfloop index="x" from="10" to="1" step="-1">
<li>#x#</li>
</cfloop>
</cfoutput>
<!--- cfscript --->
<cfscript>
for (x = 10; x > 0; x--) {
writeOutput('<li>' & x & '</li>');
}
</cfscript>
<!--- HTML Output --->
- 10
- 9
- 8
- 7
- 6
- 5
- 4
- 3
- 2
- 1功能中的CFLoop
确保在函数内部索引var或确定local索引范围。Foo()返回11。
<!--- var scope --->
<cffunction name="foo" access="public" output="false" returntype="numeric">
<cfset var x = 0 />
<cfloop index="x" from="1" to="10" step="1">
<cfset x++ />
</cfloop>
<cfreturn x />
</cffunction>
<!--- Local scope --->
<cffunction name="foo" access="public" output="false" returntype="numeric">
<cfloop index="local.x" from="1" to="10" step="1">
<cfset local.x++ />
</cfloop>
<cfreturnlocal.x/>
</cffunction>通过电流的ColdFusion11
cfscript函数cfloop不支持index作为独立的计数器机制。
热门推荐
10 高考同学留言祝福语简短
11 早餐祝福语怎么写简短
12 生日贺卡手绘祝福语简短
13 所有的新年祝福语简短
14 晚辈读大学祝福语简短
15 小升初考试后祝福语简短
16 美国护士毕业祝福语简短
17 搬家寄语祝福语大全简短
18 前程祝福语简短暖心