Mark Pearl

Something that I wasn’t aware was possible in C# was double for loops… they have the following format.

for (int x = 0, y = 0; x < 10; x++, y=x*2) { Console.Write(“{0} “, y); }
Console.ReadLine(); This would give you the following output…

0 2 4 6 8 10 12 14 16 18

In fact you can use as many variables as you want, the following would also be valid…

for (int x = 0, y = 0, z = 10; x < 10; x++, y=x*2) { Console.Write(“{0} “, z); }
Console.ReadLine();



blog comments powered by Disqus

Want to get my personal insights on what I learn as I learn it? Subscribe now!


/