Thread: Loops at same time c++ vrkiller

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    33

    Post Loops at same time c++ vrkiller

    Hello i was wondering about how i could make a loop that like runs on the same time

    Code:
    while(1)
    {
    if m=1
    cout << "lol";
    }
    while(1)
    {
    if get_key(space)
    m=1;
    else
    m=0;
    }

    remember this is just a example!

  2. #2
    بابلی ریکا Masterx's Avatar
    Join Date
    Nov 2007
    Location
    Somewhere nearby,Who Cares?
    Posts
    497
    would you please explain more! ? it somehow vague to me !(an possibly the others)
    you mean you are planning to make an infinite loop?
    Highlight Your Codes
    The Boost C++ Libraries (online Reference)

    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.."
    Bill Bryson


  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    it seems you'd like to do 2 things simultaneously.

    two ways:
    1. use threads
    2. use asynchronous processing (for example timers)
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Or perhaps you could use non-blocking input (OS-specific).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    So is your goal to write 'lol' while the spacebar is held down?

    If so, you need to use an input method that doesn't wait for you to press a key, but instead just returns the answer immediately telling you if the key is currently down or not. That's "non-blocking input".
    Then you only have one loop. Pseudocode:
    Code:
    while (true)
    {
        if (key_is_down(KEY_SPACEBAR))
            cout << "lol";
    }
    Of course you shouldn't make a busy-loop like this though.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Representing floats with color?
    By DrSnuggles in forum C++ Programming
    Replies: 113
    Last Post: 12-30-2008, 09:11 AM
  2. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 04:44 AM
  3. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 AM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM

Tags for this Thread