Infinite For Loop Syntax in C#

So they say that you learn something new everyday. They are correct today.

Digging through open source code is a great way to learn new tricks and I have been doing a fair bit of it lately - out of both necessity and curiosity. This is probably old hat to some but to me the following code is a bright and shiny hat of confusion:

            public JobDetails GetNextJobToProcess()
            {
                
//crazy for loop syntax here ...
                
for (;;)
                {
                    BaseJobStore cachedJobStore 
jobStore;
                    if 
(cachedJobStore == null)
                        
return null;

                    
JobDetails jobDetails jobStore.GetNextJobToProcessOrWaitUntilSignaled(schedulerGuid);
                    if 
(jobDetails != null)
                        
return jobDetails;
                
}
            }

Turns out that the syntax represents an infinite for loop without any initialisation, conditions or increments. Might come in handy one day and these things are always good to know. I found a great article for explaining the intricacies of the for loop at Blackwasp.

Bonus points for anyone who can recognise the project the code belongs to!!!

kick it on DotNetKicks.com

November 23, 2007 11:22 by steven.burman
E-mail | Permalink | Comments (4) | Comment RSSRSS comment feed

Related posts

Comments

November 23. 2007 11:42

trackback

Trackback from DotNetKicks.com

Infinite For Loop Syntax in C#

DotNetKicks.com

November 23. 2007 17:04

Ken Egozi

That's Castle Schedule stuff ain't it?

no super memory here, just googled it up ...

Ken Egozi

November 23. 2007 17:13

steven.burman

Spot on. First comment!

Castle.Components.Scheduler from CastleContrib

steven.burman

November 24. 2007 00:41

Dustin Campbell

Personally, I prefer a while-loop for infinite loops.

while (true)
{
// Do stuff...
}

Dustin Campbell

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

July 4. 2009 20:16