Loop over multiple arrays simultaneously: Difference between revisions

m
Line 1,593:
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">
module LoopOverMultipleArrays {
void run() {
@Inject Console console;
 
void run()
{
Char[] chars = ['a', 'b', 'c'];
String[] strings = ["A", "B", "C"];
Int[] ints = [ 1, 2, 3 ];
 
@Inject Console console;
console.print("Using array indexing:");
for (Int i = 0, Int longest = chars.size.maxOf(strings.size.maxOf(ints.size)); i < longest; ++i)
i < longest; ++i) {
console.print($|{i < chars.size ? chars[i].toString() : ""}\
|{i < strings.size ? strings[i] : ""}\
|{i < ints.size ? ints[i].toString() : ""}
);
}
 
console.print("\nUsing array iterators:");
Line 1,616 ⟶ 1,613:
val stringIter = strings.iterator();
val intIter = ints.iterator();
while (True) {
{
StringBuffer buf = new StringBuffer();
if (Char ch := charIter.next()) {
{
buf.add(ch);
}
if (String s := stringIter.next()) {
{
s.appendTo(buf);
}
if (Int n := intIter.next()) {
{
n.appendTo(buf);
}
if (buf.size == 0) {
{
break;
}
console.print(buf);
}
console.print(buf);
}
}
}
</syntaxhighlight>
 
162

edits