From b4c861e4d987023179d94d06695efe1d6933d7e1 Mon Sep 17 00:00:00 2001 From: Tom Peer Date: Mon, 15 Dec 2025 09:53:03 +0000 Subject: [PATCH 1/2] Added examples for using more advanced Lucee loops --- data/en/cfloop.json | 4 ++-- guides/en/for.md | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/data/en/cfloop.json b/data/en/cfloop.json index ff1e77269..32b4fd477 100644 --- a/data/en/cfloop.json +++ b/data/en/cfloop.json @@ -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": "" }, { @@ -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(\"
  • #currentKey# : #myStruct[currentKey]#
  • \"); \r\n } \r\n // By structEach() \r\n myStruct.each(function(key, value) { \r\n writeOutput(\"
  • #key# : #value#
  • \"); \r\n }); \r\n ", + "code": "myStruct = {name: \"Tony\", state: \"Florida\"}; \r\n // By struct \r\n for (currentKey in myStruct) { \r\n writeOutput(\"
  • #currentKey# : #myStruct[currentKey]#
  • \"); \r\n } \r\n // By structEach() \r\n myStruct.each(function(key, value) { \r\n writeOutput(\"
  • #key# : #value#
  • \"); \r\n }); \r\n // loop with index Lucee5+\nloop collection=myStruct index=\"key\" value=\"value\" {\n writeOutput(key & \" : \" & value);\n}", "result": "" }, { diff --git a/guides/en/for.md b/guides/en/for.md index 871c39c3f..32eb2e9df 100644 --- a/guides/en/for.md +++ b/guides/en/for.md @@ -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"]; @@ -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) { @@ -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"], @@ -56,7 +69,7 @@ The above example would output `appleorangebanana` writeOutput("#query.currentRow# - #row.name#
    "); } -### Query Loop (with grouping) CF10+ +### Query Loop (with grouping) CF10+ Lucee5+ q = queryNew("pk,fk,data", "integer,integer,varchar", [ [1, 10, "aa"], From 30dcfb8b4dd2fa87100532b48878622792860989 Mon Sep 17 00:00:00 2001 From: Tom Peer Date: Mon, 15 Dec 2025 09:57:15 +0000 Subject: [PATCH 2/2] Error on loop syntax --- data/en/cfloop.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/en/cfloop.json b/data/en/cfloop.json index 32b4fd477..c8adbd09d 100644 --- a/data/en/cfloop.json +++ b/data/en/cfloop.json @@ -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(\"
  • #currentKey# : #myStruct[currentKey]#
  • \"); \r\n } \r\n // By structEach() \r\n myStruct.each(function(key, value) { \r\n writeOutput(\"
  • #key# : #value#
  • \"); \r\n }); \r\n // loop with index Lucee5+\nloop collection=myStruct index=\"key\" value=\"value\" {\n writeOutput(key & \" : \" & value);\n}", + "code": "myStruct = {name: \"Tony\", state: \"Florida\"}; \r\n // By struct \r\n for (currentKey in myStruct) { \r\n writeOutput(\"
  • #currentKey# : #myStruct[currentKey]#
  • \"); \r\n } \r\n // By structEach() \r\n myStruct.each(function(key, value) { \r\n writeOutput(\"
  • #key# : #value#
  • \"); \r\n }); \r\n // loop with index Lucee5+\nloop collection=myStruct key=\"key\" value=\"value\" {\n writeOutput(key & \" : \" & value);\n}", "result": "" }, {