Wiki Talk Looping Demo
Last changed: -10.10.192.22

.
See_also

Using functions and loops to construct a table from two arrays

 :Cell: {r,c| [r, c]}
 :Row: {r, cs| [ cs.Collect{c| ["||", Cell(r, c)]}, "||", Newline]}
 :Table: {rs, cs| rs.Collect{r|Row(r, cs)}}
 @ @ Table(["A", "B", "C", "D"], [1,2,3,4,5,6]) @ @
A1 A2 A3 A4 A5 A6
B1 B2 B3 B4 B5 B6
C1 C2 C3 C4 C5 C6
D1 D2 D3 D4 D5 D6

Loop through a static list of ages

This example converts a static list of numbers into an array, then loops through the array searching for topics that have an age equal to the number.

 @@["21", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40"].Collect
 { n | ["|| ", n, "|| ", namespace.TopicsWith("Age", n).Collect{e | e.Name}, "|| ", Newline]}
 @@

Outputs...

21
30
31
32
33
34 KorbyParnell ,
35 TopicPropertyTable ,
36 DarenMay ,
37
38
39
40

Advanced examples of looping through collected values

Example code for looping through topics searching for those with a property called "Age":

 @@namespace.Topics.Collect
 { e |
 e.HasProperty("Age").
         IfTrue {["||[", e.Name, "]||", e.GetProperty("Name"), "||", e.GetProperty("Age"), "||", Newline]}
         IfFalse { "" }
 }
 @@

Outputs...

DarenMay Daren May 36
KorbyParnell Korby 34
TopicPropertyTable 35
WardCunningham Ward Aquarius
WikiTalkLoopingDemo Bob 42

Example code for that uses the Select method on Topics to find topics with an "Age" property:

 @@namespace.Topics.
         Select { e | e.HasProperty("Age")}.
         Collect {e | ["||[", e.Name, "]||", e.GetProperty("Name"), "||", e.GetProperty("Age"), "||", Newline]}
 @@
DarenMay Daren May 36
KorbyParnell Korby 34
TopicPropertyTable 35
WardCunningham Ward Aquarius
WikiTalkLoopingDemo Bob 42
Name
Age

Make a link named "link" to topics with a property called "RightBorder"

 @@[
   namespace.TopicsWith("RightBorder")
   .Collect
      { e | [
         "||", 
            "\"link\":[", e.Name, "]",
         "||",
            e.Name,
         "||",
            e.Summary,
         "||", Newline,
      ]}

]

 @@
link OdsBorders
link _NormalBorders