• Post Reply Bookmark Topic Watch Topic
  • New Topic

Control Flow - while loop question  RSS feed

 
Mervin Chan
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem with flow control.

I am testing for a few conditions:

while( (a==true)&&(b==true)&&(c==true)... )
{
do something
}

The problem is that I do not know how many conditions to test at runtime.

The items to test (a,b,c ...) are read from a text file.

If this is the case, how do i write my while loop to accomodate this?
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could consider encapsulating the condition of your while loop ...


while ( areAllConditionsSatisfied() ) {
// do something
}

Then you could implement areAllConditionsSatisfied() to behave differently depending on the arguments specified at run time.
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, you could use functors (functions which are objects)...

http://jakarta.apache.org/commons/sandbox/functor/
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of instructions does the file contain? Can you give some example lines?
 
Yosi Hendarsjah
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mervin,
You can create a method that receives array of booleans and returns a boolean value. It returnstrue if and only if all the entries in the array are true.
Need some codes? Oh c'mon, you can do it.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!