Loops/Foreach: Difference between revisions
Content added Content deleted
m (Omit from: PL/0, Tiny BASIC) |
|||
Line 1,090: | Line 1,090: | ||
=={{header|Ecstasy}}== |
=={{header|Ecstasy}}== |
||
<syntaxhighlight lang="java"> |
<syntaxhighlight lang="java"> |
||
module LoopForEach |
module LoopForEach { |
||
{ |
|||
@Inject Console console; |
@Inject Console console; |
||
void run() |
void run() { |
||
{ |
|||
val vals = [10, 20, 30, 40]; |
val vals = [10, 20, 30, 40]; |
||
console.print("Array of values:"); |
console.print("Array of values:"); |
||
Loop: for (val val : vals) |
Loop: for (val val : vals) { |
||
{ |
|||
console.print($" value #{Loop.count + 1}: {val}"); |
console.print($" value #{Loop.count + 1}: {val}"); |
||
} |
|||
Map<String, Int> pairs = ["x"=42, "y"=69]; |
Map<String, Int> pairs = ["x"=42, "y"=69]; |
||
console.print("\nKeys and values:"); |
console.print("\nKeys and values:"); |
||
for ((String key, Int val) : pairs) |
for ((String key, Int val) : pairs) { |
||
{ |
|||
console.print($" {key}={val}"); |
console.print($" {key}={val}"); |
||
} |
|||
console.print("\nJust the keys:"); |
console.print("\nJust the keys:"); |
||
Loop: for (String key : pairs) |
Loop: for (String key : pairs) { |
||
{ |
|||
console.print($" key #{Loop.count + 1}: {key}"); |
console.print($" key #{Loop.count + 1}: {key}"); |
||
} |
|||
console.print("\nValues from a range:"); |
console.print("\nValues from a range:"); |
||
for (Int n : 1..5) |
for (Int n : 1..5) { |
||
{ |
|||
console.print($" {n}"); |
console.print($" {n}"); |
||
} |
|||
} |
} |
||
} |
} |
||
} |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||