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.

Slides:



Advertisements
Similar presentations
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 6 Repetition Statements.
Advertisements

Chapter 2: Basic Elements of C++
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Computer Science 1620 Loops.
1 Session-17 CSIT 121 Spring 2006 Loops: Conditional and Count Controlled Loops: Conditional and Count Controlled LCV: Initialize; Test and Update LCV:
1 Session-16 CSIT 121 Spring 2006 Demo for switch-case due now Demo for switch-case due now String comparison String comparison Slide 23; sample case.
1 Lab Session-8 CSIT-121 Fall 2003 w Call by Reference w Lab Exercise 1 w Lab Exercise for Demo w Practice Problems.
Topic R1 – Review for the Midterm Exam. CISC 105 – Review for the Midterm Exam Exam Date & Time and Exam Format The midterm exam will be Tuesday, 3 April.
1 Session-23 CSIT 121 Spring 2006 Revision Ch 7: Reference Parameters Revision Ch 7: Reference Parameters Chapter 8: Value Returning Functions Chapter.
1 Lab Session-9 CSIT221 Fall 2002 Lab Exercise Based on operator overloading (Demo Required)
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
Chapter 5: Loops and Files.
1 Session-7 CSIT 121 Spring 2006 Lab Demo of NiMo Lesson 3-2 Exercises 1,2,3,4,5,6 (Arithmetic Operators with Program ‘Convert.cpp’) Q&A about operators.
Chapter 4 Summation.
1 Lab Session-XIV CSIT121 Spring 2002 b Namespaces b First Class Travel b Lab Exercise 14 (Demo) b Lab Exercise b Practice Problem.
1 Session-14 CSIT 121 Spring 2006 Demo due today; demo hint was sent to your campus accounts Demo due today; demo hint was sent to your campus .
1 Lab Session-IV CSIT-120 Spring 2001 Lab 3 Revision and Exercises Rev: Precedence Rules Lab Exercise 4-A Machine Language Programming The “Micro” Machine.
1 Lab Session-7 CSIT-121 Fall Revising Structured Choice 4 The While Loop variations 4 Lab Exercises.
Repetition Structures: For Loop Constants CSC 1401: Introduction to Programming with Java Week 5 Wanda M. Kunkle.
1 Lab Session-6 CSIT-121 Spring 2005 Structured Choice The do~While Loop Lab Exercises.
1 Lab Session-3 CSIT 121 Fall 2004 Section-3 should finish Lab-1 Exercise first Division rules Operator precedence rules Lab Exercise.
1 Lab Session-VII CSIT-121 Fall Revising Previous Lab and performing ASCII chart printing experiment (DEMO) 4 Visual Studio Features 4 The While.
1 Lab Session-3 CSIT 121 Spring’05 Division rules Operator precedence rules Lab Exercise.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
1 Lab Session-7 CSIT-121 Fall Introducing Structured Choice 4 The do~While Loop 4 Lab Exercises.
1 Session-9 CSIT 121 Spring 2006 Lab Demo (first 20 minutes) The correct way to do the previous lab sheet Function calls Calling void functions Calling.
1 Lab Session-VIII CSIT-121 Spring 2002 w Formatted Output w Call by Reference w Lab Exercises w File Handling w Lab Exercises.
1 Lab Session-12 CSIT121 Fall 2004 Structures and Their Usage Passing Struct Variables to Functions.
CSCI 130 for Loops Chapter 7 - A. Execution of a C Program Execution starts in main( ) Top down style –sequential flow Unrealistic to expect sequence.
Fundamentals of Python: From First Programs Through Data Structures
Fundamentals of Python: First Programs
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Chapter 4 Program Control Statements
True or False: Boolean Expression Boolean expression are expressions which evaluate to "true" or "false“ Primary operators to combine expressions: && (and),
Copyright 2009 by Pearson Education Building Java Programs Chapter 2 Lecture 2-2: The for Loop reading: 2.3 self-check: exercises: 2-14 videos: Ch.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
1 Lab Session-8 CSIT-121 Spring 2005 Call by Reference Lab Exercise for Demo Practice Problems.
Computer Programming 12 Mr. Jean May 8 th, The plan: Video clip of the day Upcoming Assessment Bot.java.
Chapter 4: Loops and Files. The Increment and Decrement Operators  There are numerous times where a variable must simply be incremented or decremented.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 4 Loops.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
Looping II (for statement). CSCE 1062 Outline  for statement  Nested loops  Compound assignment operators  Increment and decrement operators.
Lecture 15: Control Flow (cont). 2 Lecture Contents: t Design and implementation of programs illustrating linear algorithms, branch algorithms and loop.
Repetition Statements while and do while loops
Scis.regis.edu ● CS-361: Control Structures Week 6 Dr. Jesús Borrego Lead Faculty, COS Regis University 1.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
Lec 21 More Fun with Arrays: For Loops. Agenda Some backfill for Lab 20: – Using an array in an applet or class – array instance variables – using Math.random()
Loops and Files. 5.1 The Increment and Decrement Operators.
Printing with for Loops To print a character multiple times, use a for loop. for (int j = 1; j
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 16 I’m on the Inside; You’re on the Outside.
Chapter 6 - Repetition. while Loop u Simplest loop u Two parts: test expression and loop body u Pre-tested loop –Execute loop body if test true –Bypass.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
CHAPTER #7 Problem Solving with Loop. Overview Loop logical structure Incrementing Accumulating WHILE/WHILE-END FOR Nested loop Pointer Algorithmic instruction.
Introduction to Loop. Introduction to Loops: The while Loop Loop: part of program that may execute > 1 time (i.e., it repeats) while loop format: while.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
© 2006 Pearson Education Chapter 3 Part 2 More about Strings and Conditional Statements Loops (for and while) 1.
Lecture 7: Repeating a Known Number of Times
C++ Programming: CS150 For.
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Think What will be the output?
Chapter 8 The Loops By: Mr. Baha Hanene.
Building Java Programs
Building Java Programs
Chapter 2 Lecture 2-2: The for Loop reading: 2.3
Presentation transcript:

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 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 Multiplication Tables

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 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< ; j++); system("cls"); //to clear the screen

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 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 Practice Exercises Warm up exercise 1 Page 299 Warm up exercise 6 Page 300 Warm up exercise 12 Page 300