Kinetic Code Camp - Bring your skills, or lack thereof.. :dumpster_fire:

Snippet: Dumb, but occasionally useful things to do with a for loop…

Main Post → Here!

The rules & structure…


Which means that the below dumb code is perfectly valid:

for(Console.WriteLine("Hello"); true; Console.WriteLine("World!"))
{
    Console.WriteLine("Is this thing broken?");
}

Output, which repeats forever:

Hello                          <-- Init statement
Is this thing broken?          <-- Code Block
World!                         <-- Iteration statement
Is this thing broken?
World!
Is this thing broken?
World!
Is this thing broken?
World!

So, you can do some crazy stuff with for? As you can imagine, yes, yes you can.
Should you? Mmmm, most times probably not, but I imagine the more experienced of you can see how this can be used for good.

I would advise if you use “for” outside of the traditional way, to make it crystal clear in your code what you are doing, or you may confuse someone easily, including yourself! :rofl:

2 Likes