C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-04-2009, 05:14 AM   #1
Registered User
 
Join Date: Feb 2009
Posts: 22
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!
vrkiller is offline   Reply With Quote
Old 04-04-2009, 07:38 AM   #2
C\C++ beginner
 
Masterx's Avatar
 
Join Date: Nov 2007
Location: Somewhere nearby,Who Cares?
Posts: 375
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

Quote:
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning."
Rich Cook

Quote:
"...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
Masterx is offline   Reply With Quote
Old 04-04-2009, 07:46 AM   #3
CSharpener
 
vart's Avatar
 
Join Date: Oct 2006
Posts: 5,242
it seems you'd like to do 2 things simultaneously.

two ways:
1. use threads
2. use asynchronous processing (for example timers)
__________________
If I have eight hours for cutting wood, I spend six sharpening my axe.
vart is offline   Reply With Quote
Old 04-04-2009, 08:28 AM   #4
The larch
 
Join Date: May 2006
Posts: 3,082
Or perhaps you could use non-blocking input (OS-specific).
__________________
I might be wrong.

Quote:
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).
anon is offline   Reply With Quote
Old 04-04-2009, 04:41 PM   #5
Algorithm Dissector
 
iMalc's Avatar
 
Join Date: Dec 2005
Location: New Zealand
Posts: 2,476
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
iMalc is offline   Reply With Quote
Reply

Tags
c++, loops, thread, time, vrkiller

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 02:50 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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