Geeks With Blogs
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();
Posted on Saturday, June 25, 2011 2:29 PM C# | Back to top


Comments on this post: C# double & nary for loops

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © MarkPearl | Powered by: GeeksWithBlogs.net