# For loop timer?

Page 1 of 1

## 6 Replies - 178 Views - Last Post: 25 February 2018 - 01:18 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=409496&amp;s=171b54004e66c46bfcde219a728d1ff5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 FlamingBurrito15

Reputation: 0
• 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

Reputation: 0
• 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)

### #3 ndc85430

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

Reputation: 825
• 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?

### #4 Martyr2

• Programming Theoretician

Reputation: 5226
• 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.

### #5 Skydiver

• Code herder

Reputation: 6216
• 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.

### #6 FlamingBurrito15

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

## Re: For loop timer?

Posted 25 February 2018 - 01:14 PM

Ok thanks for the help

### #7 Skydiver

• Code herder

Reputation: 6216
• 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.