Repeat conditon until it retuns true

Posted on 2005-03-13
Medium Priority
Last Modified: 2010-03-31
Hi! all

I want that if the condition below failed ..  the programme will try again to execute the arguments until the condition return true...

//  if ((clickedCount <= limit) & (fireButton.includes(x, y)))

private class MouseKeeper extends MouseAdapter{ //Modified class MouseKeeper
      public void mousePressed(MouseEvent e) {

                  //locate position of mouse cursor when moused clicked
         int x = e.getX();
         int y = e.getY();
                  //if mouse clicked within firing region, create new
                  //ball and thread, and start thread
         if (fireButton.includes(x, y))
            balls.addElement(fireButton.fire(x, y));

     if ((clickedCount <= limit) & (fireButton.includes(x, y))){
          numberBalls = numberBalls - 1;
      ballsLabel.setText("Remaining Balls = " + numberBalls);

      else {
         // Try again... code here..

Question by:ZURINET
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 86

Assisted Solution

CEHJ earned 800 total points
ID: 13528304

>>if ((clickedCount <= limit) & (fireButton.includes(x, y)))


while ((clickedCount <= limit) && (fireButton.includes(x, y))){
LVL 86

Expert Comment

ID: 13528309
Sorry - misread the question. You just need to execute it in a loop really

while (keepTrying) {
    // execute the code

but it's up to your application logic when you set keepTrying to false

Author Comment

ID: 13528322
What if the first condition return true..
then the app will keep on trying..?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 86

Expert Comment

ID: 13528325
>>then the app will keep on trying..?

It'll keep trying until you tell it not to (you could do that once it's worked)

Author Comment

ID: 13528348
The system run out of memory.. ;-)
with the while statment
LVL 86

Expert Comment

ID: 13528371
Well it will if you don't tell it to stop trying at an appropriate moment ;-)

Author Comment

ID: 13528391
I want the code to minus 1 ball for every cilck.. and click should occour. when the condtion is met
((clickedCount <= limit) && (fireButton.includes(x, y)))
and then the programme should wait until the rest of the script is excuted..before repeating again...
LVL 92

Accepted Solution

objects earned 1200 total points
ID: 13530779
> The system run out of memory.. ;-)
> with the while statment

Do *not* use a while loop there.

where is your thrtead getting started?
You can use the Thread method isAlive() to check if the thread is still running, or you can take appropriate action at the end of your threads run() method

LVL 86

Expert Comment

ID: 13539452
ZURINET, perhaps you could explain why you accepted that answer?

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question