CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2009
    Posts
    63

    modifying a loop with input

    hey guys, so i am doing a project in which i need to be able to get input to alter the processes of a loop while it is running, but without disrupting the loop- so, if the user enters a character and hits enter, for instance, the value of some variable in the loop would be changed, but otherwise the loop continues on unstopped. is there a way to do this? thanks!

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: modifying a loop with input

    You will need to perform the loop in a worker thread and regularly (e.g. each iteration) check some shared resource, such as a bool variable.
    In your main thread you then set the bool variable when you want the for-loop to stop.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    Oct 2008
    Location
    Singapore
    Posts
    195

    Re: modifying a loop with input

    Quote Originally Posted by iochinome View Post
    hey guys, so i am doing a project in which i need to be able to get input to alter the processes of a loop while it is running, but without disrupting the loop- so, if the user enters a character and hits enter, for instance, the value of some variable in the loop would be changed, but otherwise the loop continues on unstopped. is there a way to do this? thanks!
    Try kbhit if you are using windows platform. Unfortunately C++ istream classes do not support asynchronous input. So, there is no standard way of doing it.

  4. #4
    Join Date
    Feb 2002
    Posts
    4,640

    Re: modifying a loop with input

    Quote Originally Posted by rohshall View Post
    Try kbhit if you are using windows platform. Unfortunately C++ istream classes do not support asynchronous input. So, there is no standard way of doing it.
    Actually, you could use a second thread. Do all your work (the loop) in the thread, and have your main thread waiting on input.

    Viggy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured