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 新年祝福语简短给孩子