October 2011
Beginner to intermediate
1200 pages
35h 33m
English
Sometimes it’s useful to build a time delay into a program. For example, you might have encountered programs that flash a message onscreen and then go on to something else before you can read the message. You end up being afraid that you’ve missed irretrievable information of vital importance. It would be much nicer if the program paused 5 seconds before moving on. The while loop is handy for producing this effect. A technique from the early days of personal computers was to make the computer count for a while to use up time:
long wait = 0;while (wait < 10000) wait++; // counting silently
The problem with this approach is that you have to change the counting limit when you change computer ...
Read now
Unlock full access