Loops at same time c++ vrkiller

This is a discussion on Loops at same time c++ vrkiller within the C++ Programming forums, part of the General Programming Boards category; Hello i was wondering about how i could make a loop that like runs on the same time Code: while(1) ...

  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
    493
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,456
    it seems you'd like to do 2 things simultaneously.

    two ways:
    1. use threads
    2. use asynchronous processing (for example timers)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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,288
    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, 08:11 AM
  2. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 03:44 AM
  3. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-02-2006, 11:46 PM
  4. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 05:00 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 09:12 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21