Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. A timed loop

A timed loop

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aquawicket
    wrote on last edited by
    #1

    Hey,,, I have a fer function that wait for input for a while... at the moment... I code it simple like this... for(i=0; i<50000000; i++){ //waiting for input } As Processes inside the loop are changing, the loop takes longer and shorter amounts of time to complete.. 3sec to 50sec. what the easiest way to set up a timed loop that loops the same amount of time every time? Example: While ( time < 10Seconds ){ //wait for input }

    N 1 Reply Last reply
    0
    • A aquawicket

      Hey,,, I have a fer function that wait for input for a while... at the moment... I code it simple like this... for(i=0; i<50000000; i++){ //waiting for input } As Processes inside the loop are changing, the loop takes longer and shorter amounts of time to complete.. 3sec to 50sec. what the easiest way to set up a timed loop that loops the same amount of time every time? Example: While ( time < 10Seconds ){ //wait for input }

      N Offline
      N Offline
      namy1
      wrote on last edited by
      #2

      Hi!!, u can put a counter inside the loop that increments to a particular no every time e.g. int count=0 for(i=1;i<=50000000;i++) count = count+i

      A 1 Reply Last reply
      0
      • N namy1

        Hi!!, u can put a counter inside the loop that increments to a particular no every time e.g. int count=0 for(i=1;i<=50000000;i++) count = count+i

        A Offline
        A Offline
        aquawicket
        wrote on last edited by
        #3

        Later I'll be adding a "wait time option" so I gotta go by time... Just looking for the easiest way to code in a timer into a loop.

        A 1 Reply Last reply
        0
        • A aquawicket

          Later I'll be adding a "wait time option" so I gotta go by time... Just looking for the easiest way to code in a timer into a loop.

          A Offline
          A Offline
          aquawicket
          wrote on last edited by
          #4

          Ok.. I think I figured out the easiest way :) DWORD dwStart = GetTickCount(); while( GetTickCount() - dwStart < WAITTIME ){ //loop for WAITTIME milliseconds }

          C 1 Reply Last reply
          0
          • A aquawicket

            Ok.. I think I figured out the easiest way :) DWORD dwStart = GetTickCount(); while( GetTickCount() - dwStart < WAITTIME ){ //loop for WAITTIME milliseconds }

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #5

            What about WM_TIMER ?

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups