Three Special Structures – Case, Do While, and Do Until

Slides:



Advertisements
Similar presentations
CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
Advertisements

Chapter 2: Understanding Structure
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
Understanding the Three Basic Structures
Lesson 5 - Decision Structure By: Dan Lunney
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
Do/Loops A loop repeats a series of instructions. An iteration is a single execution of the statement(s) in the loop. Used when the exact number of iterations.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Chapter 6 - Repetition. Introduction u Many applications require certain operations to be carried out more than once. Such situations require repetition.
Chapter 5: Control Structures II (Repetition)
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
1 Fall 2008ACS-1903 Ch 4 Loops and Files while loop do-while loop Other topics later on …
1 Fall 2007ACS-1903 Ch 4 Loops and Files Increment & decrement statements while loop do-while loop Other topics later on …
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Programming Logic and Design Fourth Edition, Introductory
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
Invitation to Computer Science, Java Version, Second Edition.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
S2008Final_part1.ppt CS11 Introduction to Programming Final Exam Part 1 S A computer is a mechanical or electrical device which stores, retrieves,
Programming Logic and Design Fourth Edition, Comprehensive Chapter 6 Looping.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding the Three Basic Structures Structure: a basic unit of programming logic Any program.
An Object-Oriented Approach to Programming Logic and Design Chapter 5 Making Decisions.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
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.
Programming Logic and Design Fifth Edition, Comprehensive
Programming Logic and Design Fourth Edition, Comprehensive Chapter 5 Making Decisions.
1 Fall 2009ACS-1903 Ch 4 Loops and Files while loop do-while loop for loop Other topics later on …
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
An Introduction to Programming with C++ Sixth Edition Chapter 8 More on the Repetition Structure.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Topic 4: Looping Statements
Java Programming Fifth Edition
Chapter 5: Control Structures II (Repetition)
Chapter 3: Decisions and Loops
The switch Statement, and Introduction to Looping
Programming Logic and Design Fourth Edition, Comprehensive
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Control Structures II (Repetition)
Chapter 5: Repetition Structures
Chapter 4: Decision Structures and Boolean Logic
CONTROL FLOW TESTING.
Using the Priming Read Priming read (or priming input):
Loop Control Structure.
IF if (condition) { Process… }
Outline Altering flow of control Boolean expressions
While Loops and If-Else Structures
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Understanding the Three Basic Structures
Chapter 4: Decision Structures and Boolean Logic
Iteration Implemented through loop constructs (e.g., in C++)
Chapter 8: More on the Repetition Structure
Logical Operations In Matlab.
A LESSON IN LOOPING What is a loop?
Class 4: Repetition Pretest Posttest Counting Flowchart these!
Program Flow.
Decisions, decisions, decisions
True / False Variables.
Chapter 3: Selection Structures: Making Decisions
Chapter 4: Decision Structures and Boolean Logic
Presentation transcript:

Three Special Structures – Case, Do While, and Do Until Many languages allow three additional structures: case structure do-while structure do-until structure Case Structure: Decisions with more than two alternatives Tests a variable against a series of values and takes action based on a match Nested if-then-else statements will do what a case structure does Programming Logic and Design, Introductory, Fourth Edition

Three Special Structures – Case, Do While, and Do Until (continued) Using nested if-then-else for multiple alternatives Programming Logic and Design, Introductory, Fourth Edition

Three Special Structures – Case, Do While, and Do Until (continued) Using a case structure for multiple alternatives Programming Logic and Design, Introductory, Fourth Edition

Three Special Structures – Case, Do While, and Do Until (continued) do-while and do-until loops Question is asked at the end of the loop structure Ensures that the loop statements are always used at least once Programming Logic and Design, Introductory, Fourth Edition

Three Special Structures – Case, Do While, and Do Until (continued) do-while loop executes as long as the question’s answer is Yes or True Test checked at beginning May not be executed do-until loop executes as long as the question’s answer is No or False (until it becomes Yes or True) Test checked at end of loop Will always execute loop at least once Programming Logic and Design, Introductory, Fourth Edition

Three Special Structures – Case, Do While, and Do Until (continued) while loop with question at beginning is called a pretest loop do-until with question at end are called posttest loops Programming Logic and Design, Introductory, Fourth Edition

Three Special Structures – Case, Do While, and Do Until (continued) Programming Logic and Design, Introductory, Fourth Edition

Three Special Structures – Case, Do While, and Do Until (continued) Programming Logic and Design, Introductory, Fourth Edition