Difference between revisions of "Multiple expressions in for loops"

From CodeCodex

(Java)
 
(Implementations)
Line 2: Line 2:
 
===Java===  
 
===Java===  
 
You do it "à la C".  
 
You do it "à la C".  
<highlightsyntax language="java122">
+
<pre class="java">
 
public class MultipleFor{
 
public class MultipleFor{
 
   public static void main (String [] args){
 
   public static void main (String [] args){
Line 9: Line 9:
 
     }
 
     }
 
}
 
}
</highlightsyntax>
+
</pre>
 +
 
 +
=== Tcl ===
 +
<pre class="tcl">
 +
for {set i 0;set j 0} {$i < 10} {incr i;incr j -1} {puts "i = $i j = $j"}
 +
</pre>
 +
 
 
[[Category:Java]]
 
[[Category:Java]]
 +
[[Category:Tcl]]

Revision as of 14:44, 20 February 2011

Implementations

Java

You do it "à la C".

public class MultipleFor{
  public static void main (String [] args){
    for (int i=0, j=0; i < 10; i++, j--)
      System.out.println ("i = " + i + " j= " + j);
    }
}

Tcl

for {set i 0;set j 0} {$i < 10} {incr i;incr j -1} {puts "i = $i j = $j"}