Click here to Skip to main content
12,702,980 members (29,413 online)
Click here to Skip to main content
Alternatives (5)
Add your own
alternative version

Tagged as


17 bookmarked

Call Functions Until One Meets Condition

, 1 May 2012 CPOL
Call a series of functions until the return value meets a condition without a chained-if or short-circuiting.


Members may post updates or alternatives to this current article in order to show different approaches or add new features.

2 Apr 2011
VB.NET Version (C# Version)Thanks to cechode for inspiring this tip/trick. Suppose you have the following functions:Function Step1() As Boolean Return TrueEnd FunctionFunction Step2(ByVal val1 As Integer, ByVal val2 As Integer) As Boolean Return val1 = val2End...
6 Apr 2011
Member 4694807
Sorry, but I don't like adding additional artificial elements like function arrays . I would code it as following:If isok(Step1()) OrElse isok(Step2(1,1)) OrElse isok(Step3() OrElse isok(Step4() OrElse isok(0+1) thenend ifFunction isok(ByVal rc as Integer) As Boolean ...
29 Mar 2011
Sorry, but could not resist :)Being that we we started with select case (in the launge), I felt that this was missing both the initial condition and the action to perform for the case that got hit.So given this:static Action SelectCase(T conditionValue, List<System.Tuple<Func<T,...
24 Jun 2011
I do think the approach is over complicated, but in some cases there may be (a small) benefit. As an alternative I would offer:First version (no common test):((Action)(() =>{ if (!Step1()) return; if (!Step2()) return;}))();Second version (common...


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


About the Author

Web Developer
United States United States

  • Managing Your JavaScript Library in ASP.NET (if you work with and you don't read that, you are dead to me).

  • Graduated summa cum laude with a BS in Computer Science.

  • Wrote some articles and some tips.

  • DDR ("New high score? What does that mean? Did I break it?"), ping pong, and volleyball enthusiast.

  • Software I have donated to (you should too):

| | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 1 May 2012
Article Copyright 2011 by AspDotNetDev
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid