Skip to content

Commit b4c861e

Browse files
committed
Added examples for using more advanced Lucee loops
1 parent 5ce4e27 commit b4c861e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

data/en/cfloop.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
{
5252
"title": "Loop Over an Array (Script Syntax)",
5353
"description": "Array Loop",
54-
"code": "myArray = [\"a\", \"b\", \"c\"];\n// For Loop By index for CF9.0.0 and lower \nfor (i = 1; i <= arrayLen(myArray); i++) {\n writeOutput(myArray[i]);\n}\n// By For In CF9.0.1+ \nfor (currentIndex in myArray) {\n writeOutput(currentIndex);\n}\n// By arrayEach() member function CF11+\nmyArray.each(function(element, index) {\n writeOutput(element & \" : \" & index);\n});",
54+
"code": "myArray = [\"a\", \"b\", \"c\"];\n// For Loop By index for CF9.0.0 and lower \nfor (i = 1; i <= arrayLen(myArray); i++) {\n writeOutput(myArray[i]);\n}\n// By For In CF9.0.1+ \nfor (currentIndex in myArray) {\n writeOutput(currentIndex);\n}\n// By arrayEach() member function CF11+\nmyArray.each(function(element, index) {\n writeOutput(element & \" : \" & index);\n});\n// loop with index Lucee5+\nloop collection=cars index=\"i\" value=\"value\" {\n writeOutput(i & \" : \" & value);\n}",
5555
"result": ""
5656
},
5757
{
@@ -63,7 +63,7 @@
6363
{
6464
"title": "Loop over a Struct (Script Syntax)",
6565
"description": "Struct Loop",
66-
"code": "myStruct = {name: \"Tony\", state: \"Florida\"}; \r\n // By struct \r\n for (currentKey in myStruct) { \r\n writeOutput(\"<li>#currentKey# : #myStruct[currentKey]#</li>\"); \r\n } \r\n // By structEach() \r\n myStruct.each(function(key, value) { \r\n writeOutput(\"<li>#key# : #value#</li>\"); \r\n }); \r\n ",
66+
"code": "myStruct = {name: \"Tony\", state: \"Florida\"}; \r\n // By struct \r\n for (currentKey in myStruct) { \r\n writeOutput(\"<li>#currentKey# : #myStruct[currentKey]#</li>\"); \r\n } \r\n // By structEach() \r\n myStruct.each(function(key, value) { \r\n writeOutput(\"<li>#key# : #value#</li>\"); \r\n }); \r\n // loop with index Lucee5+\nloop collection=myStruct index=\"key\" value=\"value\" {\n writeOutput(key & \" : \" & value);\n}",
6767
"result": ""
6868
},
6969
{

guides/en/for.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ The above would output `321`
2424

2525
The above outputs `AB`
2626

27+
Using `loop` you can loop over the key and values (Lucee5+)
28+
29+
loop collection=st key="key" value="value" {
30+
writeOutput(key & " " & value);
31+
}
32+
33+
2734
### For In Loop (over an array) CF9.0.1+
2835

2936
cars = ["Ford","Dodge"];
@@ -35,7 +42,13 @@ The above example would output `FordDodge`
3542

3643
For in support for native Java arrays was added in CF10+
3744

38-
### For In Loop (over a list) CF10+
45+
Using `loop` you can track the index and the value (Lucee5+)
46+
47+
loop collection=cars index="i" value="value" {
48+
writeOutput("#i#: #value#");
49+
}
50+
51+
### For In Loop (over a list) CF10+ Lucee5+
3952

4053
fruits = "apple,orange,banana";
4154
for (fruit in fruits) {
@@ -44,7 +57,7 @@ For in support for native Java arrays was added in CF10+
4457

4558
The above example would output `appleorangebanana`
4659

47-
### For In Loop (over a query) CF10+
60+
### For In Loop (over a query) CF10+ Lucee5+
4861

4962
query = queryNew("name", "varchar", [
5063
["apple"],
@@ -56,7 +69,7 @@ The above example would output `appleorangebanana`
5669
writeOutput("#query.currentRow# - #row.name#<br>");
5770
}
5871

59-
### Query Loop (with grouping) CF10+
72+
### Query Loop (with grouping) CF10+ Lucee5+
6073

6174
q = queryNew("pk,fk,data", "integer,integer,varchar", [
6275
[1, 10, "aa"],

0 commit comments

Comments
 (0)