Loop speed

This is a discussion on Loop speed within the C++ Programming forums, part of the General Programming Boards category; Hi, I asked my computer programming teacher if there was a way to slow a loop down...she said yes but ...

  1. #1
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36

    Loop speed

    Hi, I asked my computer programming teacher if there was a way to slow a loop down...she said yes but she wasn't sure how...can someone here tell me how to slow the loop down...so I can make it loop every 5 seconds etc... Thanks

    -Nick

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    this is os specific and sometimes compiler specific too.

    I have used sleep() from dos.h
    Sleep() from windows.h

    some compilers also offer a delay() function. Check for those in your helpfiles.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36
    I am fairly new at this code so can you include a sample code
    Thanks I appreciate it.

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Code:
    #include<windows.h>
    #include<iostream>
    using namespace std;
    
    int main()
    {
    cout<<"This should appear straight away"<<endl;
    Sleep(5000); // millisecs
    cout<<"This should appear roughly 5 secs after"<<endl;
    return 0;
    }
    not tried it.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User quiksilver9531's Avatar
    Join Date
    Nov 2001
    Posts
    36
    it worked ...but whats this "using namespace std;" that gave me an error so I took it out and it worked. What does that do?

    Thanks for the code
    -Nick

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  2. Visual Studio Express / Windows SDK?
    By cyberfish in forum C++ Programming
    Replies: 23
    Last Post: 01-22-2009, 01:13 AM
  3. syntax question
    By cyph1e in forum C Programming
    Replies: 19
    Last Post: 03-30-2006, 11:59 PM
  4. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM
  5. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 08:15 AM

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