6 Replies - 178 Views - Last Post: 25 February 2018 - 01:18 PM Rate Topic: -----

#1 FlamingBurrito15   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 13-December 17

For loop timer?

Posted 25 February 2018 - 12:56 PM

Hello just out of curiosity what number in a for loop would equal 10 seconds?

(Like
for(I = 0; I < 28; I++)
would equal to 3 seconds)
Is This A Good Question/Topic? 0
  • +

Replies To: For loop timer?

#2 FlamingBurrito15   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 13-December 17

Re: For loop timer?

Posted 25 February 2018 - 12:58 PM

Hello just out of curiosity what number in a for loop would equal 3 seconds?

(Like
for(I = 0; I < 28; I++)
would equal to 4 seconds)
Was This Post Helpful? 0
  • +
  • -

#3 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 825
  • View blog
  • Posts: 3,337
  • Joined: 13-June 14

Re: For loop timer?

Posted 25 February 2018 - 01:03 PM

What? Your question doesn't really make any sense. What do you mean when you say that for loop "would equal to 3 seconds"? More to the point, though, what problem are you really trying to solve?
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5226
  • View blog
  • Posts: 14,005
  • Joined: 18-April 07

Re: For loop timer?

Posted 25 February 2018 - 01:05 PM

You can't gauge time like that. The loops execution is independent of system time. The speed of the loop would be effected by current CPU cycles, what else is running, available RAM etc. If you are looking to implement some kind of delay, then look at the sleep() function which will allow you to pause for a specific period of time.
Was This Post Helpful? 1
  • +
  • -

#5 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6216
  • View blog
  • Posts: 21,455
  • Joined: 05-May 12

Re: For loop timer?

Posted 25 February 2018 - 01:05 PM

There is no well defined value. Each computer runs at a different rate. Your best bet is to loop and look at the elapsed time instead of some fixed loop value.
Was This Post Helpful? 0
  • +
  • -

#6 FlamingBurrito15   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 13-December 17

Re: For loop timer?

Posted 25 February 2018 - 01:14 PM

Ok thanks for the help :smile2:
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6216
  • View blog
  • Posts: 21,455
  • Joined: 05-May 12

Re: For loop timer?

Posted 25 February 2018 - 01:18 PM

+1 for using sleep(). Looping waiting for the elapsed time consumes for CPU power while sleep() tells the OS to reactivate your program after at least that amount of time has passed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1