Click here to Skip to main content
13,248,766 members (45,857 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 19 Jun 2012

Call Functions Until One Meets Condition

, 19 Jun 2012
Rate this:
Please Sign up or sign in to vote.
This is an alternative for "Call Functions Until One Meets Condition"


This is an alternative tip to the original tip[^].

It basically wraps the original tip into one function. I prefer wrapping such functionality into a function that tells about the intent of the construct (even some purists will argue that function calls cost execution time...).

Here comes the code:

public static void RunToFirstMatch<T>(Func<T, bool> sentry, params Func<T>[] functions)
    functions.Any(f => sentry(f()));

The code is called as follows (see the original functions[^]):

RunToFirstMatch(v => (v >= 5), Step1, ()=>Step2(1,1), Step3, Step4, ()=>0+1);

As said, the content is the same, I simply added some wrapping.


  • V1.0, 2012-06-19: Initial version
  • V1.1, 2012-06-19: Fixed code


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Andreas Gieriet
Founder eXternSoft GmbH
Switzerland Switzerland
I feel comfortable on a variety of systems (UNIX, Windows, cross-compiled embedded systems, etc.) in a variety of languages, environments, and tools.
I have a particular affinity to computer language analysis, testing, as well as quality management.

More information about what I do for a living can be found at my LinkedIn Profile and on my company's web page (German only).

You may also be interested in...


Comments and Discussions

SuggestionTypo / Notes Pin
AspDotNetDev19-Jun-12 19:34
protectorAspDotNetDev19-Jun-12 19:34 
GeneralRe: Typo / Notes Pin
Andreas Gieriet19-Jun-12 21:46
memberAndreas Gieriet19-Jun-12 21:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 20 Jun 2012
Article Copyright 2012 by Andreas Gieriet
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid