• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Control Flow - while loop question

 
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?
 
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.
 
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/
 
(instanceof Sidekick)
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?
 
Ranch Hand
Posts: 168
Java
  • 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.
 
Hold that thought. Tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!