Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Session-19 CSIT 121 Spring 2006 Count controlled loops can be implemented with for statement This statement becomes the loop header for (lcv=initial.

Similar presentations


Presentation on theme: "1 Session-19 CSIT 121 Spring 2006 Count controlled loops can be implemented with for statement This statement becomes the loop header for (lcv=initial."— Presentation transcript:

1 1 Session-19 CSIT 121 Spring 2006 Count controlled loops can be implemented with for statement This statement becomes the loop header for (lcv=initial value; lcv<=final value; lcv modification statement) For example; we have to evaluate factorial of a number. If we use a for loop, it will be quick and simple

2 2 Count Controlled Nested Loops You can embed loops within loops (nested loops) It may be useful when processing data in separate categories The task may be performing repetitive operations and the task itself may be repetitive Example: A program displays multiplication tables for numbers 1 through 10 as on the next page A clock is incrementing seconds and after 60 seconds it increments minutes and after 60 minutes, it increments hours. Thus it is performing repetitive operations.

3 3 Multiplication Tables

4 4 Lab Demo Due April 11th Design a program that simulates a digital clock. When the program starts running, it displays the following time: 00:00:00 Later, the program starts changing the time just like a clock would do. For example, the next display would be: 00:00:01

5 5 Help: Familiar Format Instead of using Sleep() function with a changed format of the program, you may want to waste about one second with this idle loop. Plug it in to your program where you need the delay of one second: for (int j=0; j<500000000; j++); system("cls"); //to clear the screen

6 6 Help: Unfamiliar Format Instead of : #include Using namespace std; Use the following directives (Old C Style): #include Then use the following line to sleep for one second: Sleep(1000);

7 7 Help: Both Formats You also need the following statements to set the format of your output: cout.setf(ios::fixed | ios::right); cout.fill('0'); //leading zeroes displayed

8 8 Practice Exercises Warm up exercise 1 Page 299 Warm up exercise 6 Page 300 Warm up exercise 12 Page 300


Download ppt "1 Session-19 CSIT 121 Spring 2006 Count controlled loops can be implemented with for statement This statement becomes the loop header for (lcv=initial."

Similar presentations


Ads by Google