Topics discussed in this section:

Slides:



Advertisements
Similar presentations
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Advertisements

WARM-UP: MON, APR 7 What are loops used for in programming? What are at least 2 different kinds of loops?
LOOP / REPETITION while loop. for loop do/while loop We assume that loops are not meant to be infinite. That is, there should always be a way out of the.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
Chapter 5: Control Structures II (Repetition)
CS1061: C Programming Lecture 8: Repetition A. O’Riordan, 2004.
Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into.
Chapter 5: Repetition Statements. In this chapter, you will learn about: Basic loop structures while loops Interactive while loops for loops Loop programming.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand basic loop concepts: ■ pretest loops and post-test loops ■ loop.
Control Structures - Repetition Chapter 5 2 Chapter Topics Why Is Repetition Needed The Repetition Structure Counter Controlled Loops Sentinel Controlled.
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
Chapter 4: Looping. Resource: Starting Out with C++, Third Edition, Tony Gaddis 5.1 The Increment and Decrement Operators ++ and -- are operators that.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
C++ for Engineers and Scientists, Third Edition1 Objectives In this chapter, you will learn about: Basic loop structures while loops Interactive while.
sequence of execution of high-level statements
By Chad Blankenbeker.  The for-loop is best used when you know how many times it is going to be looped  So if you know you want it to only loop 10 times,
1 Objectives ❏ To understand basic loop concepts: ■ pretest loops and post-test loops ■ loop initialization and updating ■ event and counter controlled.
Computer Science: A Structured Programming Approach Using C1 5-3 Multiway Selection In addition to two-way selection, most programming languages provide.
Overview of Java Loops By: Reid Hunter. What Is A Loop? A loop is a series of commands that will continue to repeat over and over again until a condition.
CHAPTER 3 CONTROL STRUCTURES ( REPETITION ) I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Control Structures sequence of execution of high-level statements.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Looping Construct or Statements. Introduction of looping constructs In looping,a sequence of statements are executed until some condition for termination.
Computer Science By: Erica Ligons Compound Statement A compound statement- block A compound statement- is a unit of code consisting of zero or more statement.
Repetition Statements (Loops) The do while Loop The last iteration structure in C++ is the do while loop. A do while loop repeats a statement or.
Computer Science: A Structured Programming Approach Using C1 6-6 Loop Examples This section contains several short examples of loop applications. Each.
Repetition Repetition allows you to repeat an operation or a series of operations many times. This is called looping and is one of the basic structured.
1 1 Additional Control Structures Chapter 9 2 New and Improved... Ways to branch Ways to write loops Understanding the break and continue statements.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Computer Science: A Structured Programming Approach Using C1 5-5 Incremental Development Part II In Chapter 4, we introduced the concept of incremental.
Computer Science: A Structured Programming Approach Using C1 5-5 Incremental Development Part II In Chapter 4, we introduced the concept of incremental.
While ( number
1 CSC103: Introduction to Computer and Programming Lecture No 9.
Chapter 5: Looping. Using the while Loop Loop – A structure that allows repeated execution of a block of statements Loop body – A block of statements.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand how decisions are made in a computer ❏ To understand the logical.
Topic 4: Looping Statements
Statements (6 of 6) A statement causes an action to be performed by the program. It translates directly into one or more executable computer instructions.
Selection—Making Decisions
Topics discussed in this section:
Quick Test What do you mean by pre-test and post-test loops in C?
( Iteration / Repetition / Looping )
Computer Science Faculty
Loops in C C has three loop statements: the while, the for, and the do…while. The first two are pretest loops, and the the third is a post-test loop. We.
الحلقات التكرارية وجمل الدوران (loops)
Chapter 6 Repetition Objectives ❏ To understand basic loop concepts:
FIGURE 4-10 Function Return Statements
Topics discussed in this section:
Topics discussed in this section:
- Additional C Statements
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
INC 161 , CPE 100 Computer Programming
Structured Program Development in C
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
Topics discussed in this section:
LOOPS BY: LAUREN & ROMEO.
Chapter 6: Repetition Statements
FIGURE 4-10 Function Return Statements
4-2 Functions in C In C, the idea of top–down design is done using functions. A C program is made of one or more functions, one and only one of which.
Topics discussed in this section:
More Loops Topics Counter-Controlled (Definite) Repetition
Dale Roberts, Lecturer IUPUI
Programming Right from the Start with Visual Basic .NET 1/e
Introduction to Computer Science
FIGURE 4-10 Function Return Statements
More Loops Topics Counter-Controlled (Definite) Repetition
Lec 6 Loop Statements Introduction to Computer Programming
More Loops Topics Counter-Controlled (Definite) Repetition
Presentation transcript:

Topics discussed in this section: 6-5 Loops in C C has three loop statements: the while, the for, and the do…while. The first two are pretest loops, and the the third is a post-test loop. We can use all of them for event-controlled and counter-controlled loops. Topics discussed in this section: The while Loop The for Loop The do…while Loop The Comma Expression Computer Science: A Structured Programming Approach Using C

FIGURE 6-9 C Loop Constructs Computer Science: A Structured Programming Approach Using C

FIGURE 6-10 The while Statement Computer Science: A Structured Programming Approach Using C

FIGURE 6-11 Compound while Statement Computer Science: A Structured Programming Approach Using C

Process-control System Example PROGRAM 6-1 Process-control System Example Computer Science: A Structured Programming Approach Using C

A while Loop to Print Numbers PROGRAM 6-2 A while Loop to Print Numbers Computer Science: A Structured Programming Approach Using C

A while Loop to Print Numbers PROGRAM 6-2 A while Loop to Print Numbers Computer Science: A Structured Programming Approach Using C

Adding a List of Numbers PROGRAM 6-3 Adding a List of Numbers Computer Science: A Structured Programming Approach Using C

Adding a List of Numbers PROGRAM 6-3 Adding a List of Numbers Computer Science: A Structured Programming Approach Using C

more natural for counting loops. Note A for loop is used when a loop is to be executed a known number of times. We can do the same thing with a while loop, but the for loop is easier to read and more natural for counting loops. Computer Science: A Structured Programming Approach Using C

FIGURE 6-14 Comparing for and while Loops Computer Science: A Structured Programming Approach Using C

PROGRAM 6-4 Example of a for Loop Computer Science: A Structured Programming Approach Using C

PROGRAM 6-4 Example of a for Loop Computer Science: A Structured Programming Approach Using C

A Simple Nested for Loop PROGRAM 6-5 A Simple Nested for Loop Computer Science: A Structured Programming Approach Using C

A Simple Nested for Loop PROGRAM 6-5 A Simple Nested for Loop Computer Science: A Structured Programming Approach Using C

FIGURE 6-15 do…while Statement Computer Science: A Structured Programming Approach Using C

PROGRAM 6-6 Two Simple Loops Computer Science: A Structured Programming Approach Using C

PROGRAM 6-6 Two Simple Loops Computer Science: A Structured Programming Approach Using C

FIGURE 6-16 Pre- and Post-test Loops Computer Science: A Structured Programming Approach Using C

Adding a List with the do…while PROGRAM 6-7 Adding a List with the do…while Computer Science: A Structured Programming Approach Using C

Adding a List with the do…while PROGRAM 6-7 Adding a List with the do…while Computer Science: A Structured Programming Approach Using C

FIGURE 6-17 Nested Comma Expression Computer Science: A Structured Programming Approach Using C

Comparison of while and do…while PROGRAM 6-8 Comparison of while and do…while Computer Science: A Structured Programming Approach Using C

Comparison of while and do…while PROGRAM 6-8 Comparison of while and do…while Computer Science: A Structured Programming Approach Using C