LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-16-2006, 07:16 PM   #1
linuxmandrake
Member
 
Registered: Sep 2004
Distribution: debian sarge 64bit (AMD)
Posts: 709

Rep: Reputation: 30
temporily suspending the execution of loop to allow other method to run


while(still==true)
{
repairs();
}

public void move()
{
still=false;
}

basically when I have killed an enemy and remain still then repairs on the ship will take place. However the user can stop this by moving. He does this by clicking on a button which executes move() hence the loop should terminate. Is that possible?

Last edited by linuxmandrake; 04-16-2006 at 07:18 PM.
 
Old 04-16-2006, 07:56 PM   #2
axelfc
Member
 
Registered: Jan 2006
Distribution: ArchLinux
Posts: 175

Rep: Reputation: 34
Check out this code i have written. The program runs a loop which prints on the screen OK and stops when you press a button from the keyboard. I think it will help you.
Code:
import java.io.*;

public class InfiniteLoopExit implements Runnable {

    public static void main( String[] args ) {
        InfiniteLoopExit ile = new InfiniteLoopExit();
        Thread t = new Thread( ile );
        t.start();
        InputStreamReader isr = new InputStreamReader ( System.in );
        BufferedReader br = new BufferedReader ( isr );
        String s = null;
        try {
            while ( (s = br.readLine ()) != null ) {
                System.out.println( "Done!!" );
                System.exit(0);
            }
        }
        catch ( IOException ioe ) {}
    }
    public void run() {
        while ( true ) {
            System.out.println( "OK" );
            try { 
                Thread.sleep( 1000 ); 
            } catch (InterruptedException ie ) {}
        }
    }
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Method Not Allowed: The requested method POST is not allowed for the URL /writedhcp.p WiWa Linux - Networking 15 01-06-2011 01:20 PM
SlackWare :Method Not Allowed The requested method POST is not allowed for the URL slack31337 Linux - Software 0 04-08-2006 06:09 PM
Loop ends unexpectedly after one run! trex_dk Programming 2 11-11-2005 03:49 AM
Error while trying to run exec method with rsh as arguement nedian123 Programming 0 12-18-2004 12:07 AM
loop execution suchi_s Programming 4 11-05-2004 08:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration