Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #657

Re: question on a generic program logic issue

From Willem <willem@toad.stack.nl>
Newsgroups alt.comp.lang.learn.c-c++, comp.programming
Subject Re: question on a generic program logic issue
Date 2011-07-16 09:05 +0000
Organization Stack Usenet News Service
Message-ID <slrnj22l2h.2d5n.willem@toad.stack.nl> (permalink)
References <9sb227hu62qg7afpfvghvi0iuqflboe7nn@4ax.com>

Cross-posted to 2 groups.

Show all headers | View raw


NoName wrote:
) I'm trying to figure out how to do something in code, fairly
) efficiently, using fairly standard programming constructs.  The exact
) language doesn't matter, could be C, C++, Java, Visual Basic, C#, etc.
)
) The idea is this.  I want to have some code that basically says:
)
) if (condition1 and/or condition2 and/or condition3) then?.
)
) where the "and/or" is determined by some kind of flag that can be set
) dynamically.  Viewed another way, in pseudocode, I want:

Is there only one flag that determines both and/or choices ?

Then I dont think you can do much better than:

 if ((and_flag && c1 && c2 && c3) || (!and_flag && (c1 || c2 || c3))) {
 }

Perhaps you can reduce that a bit with some boolean algebra,
but I doubt you can reduce it a lot.  Off the top of my head,
you can drop the first use of 'and_flag'.

If you have two separate flags, it becomes a lot more complicated.
Then you may be better off looking at decision tables.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

question on a generic program logic issue NoName <null@null.com> - 2011-07-16 02:37 -0400
  Re: question on a generic program logic issue kym@kymhorsell.com - 2011-07-16 06:52 +0000
  Re: question on a generic program logic issue Willem <willem@toad.stack.nl> - 2011-07-16 09:05 +0000
  Re: question on a generic program logic issue Keith Thompson <kst-u@mib.org> - 2011-07-16 10:46 -0700
  Re: question on a generic program logic issue Willem <willem@toad.stack.nl> - 2011-07-18 10:09 +0000

csiph-web