S2 Cookbook: Logic and Flow Control
From Dreamwidth Notes
Contents
Perform actions based on conditions
Cycle through every member of an array
var string[] items = ["sock", "pants", "shirt", "skirt", "scarf"]; print "<ul>"; foreach var string item ( $items ) { print "<li>$item</li>"; } print "</ul>";
Cycle through every member of an associative array
var string{} fruits = {"apple" => "red", "lemon" => "yellow", "grape" => "purple"}; print "<ul>"; foreach var string fruit ( $fruits ) { var string color = $fruits{$fruit}; print "<li>$fruit: $color</li>"; } print "</ul>";