Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions data/en/cfloop.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
{
"title": "Loop Over an Array (Script Syntax)",
"description": "Array Loop",
"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});",
"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}",
"result": ""
},
{
Expand All @@ -63,7 +63,7 @@
{
"title": "Loop over a Struct (Script Syntax)",
"description": "Struct Loop",
"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 ",
"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 key=\"key\" value=\"value\" {\n writeOutput(key & \" : \" & value);\n}",
"result": ""
},
{
Expand Down
19 changes: 16 additions & 3 deletions guides/en/for.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ The above would output `321`

The above outputs `AB`

Using `loop` you can loop over the key and values (Lucee5+)

loop collection=st key="key" value="value" {
writeOutput(key & " " & value);
}


### For In Loop (over an array) CF9.0.1+

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

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

### For In Loop (over a list) CF10+
Using `loop` you can track the index and the value (Lucee5+)

loop collection=cars index="i" value="value" {
writeOutput("#i#: #value#");
}

### For In Loop (over a list) CF10+ Lucee5+

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

The above example would output `appleorangebanana`

### For In Loop (over a query) CF10+
### For In Loop (over a query) CF10+ Lucee5+

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

### Query Loop (with grouping) CF10+
### Query Loop (with grouping) CF10+ Lucee5+

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