Structured Programming The Basics. Control structures They control the order of execution What order statements will be done in, or whether they will.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Chapter 7 - Iteration. Chapter Goals Program repitiation statements – or loops – with the for, while, and do-while statements Program repitiation statements.
While loops.
How SAS implements structured programming constructs
Dependency Analysis We want to “parallelize” program to make it run faster. For that, we need dependence analysis to ensure correctness.
Introduction to Flowcharting
CS0004: Introduction to Programming Repetition – Do Loops.
Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition.
Loop Statements (Iteration). Iteration  A portion of a program that repeats a statement or group of statements is called a loop.  Each repetition of.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Control Structures - Repetition Chapter 5 2 Chapter Topics Why Is Repetition Needed The Repetition Structure Counter Controlled Loops Sentinel Controlled.
Chapter 2 Control. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. Repetition, quick overview.
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
1 Chapter 1 Overview of Programming and Problem Solving Dale/Weems Slides based on work by Sylvia Sorkin, Community College of Baltimore County - Essex.
CONTROL FLOW IN C++ Satish Mishra PGT CS KV Trimulgherry.
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
Logic Structure - focus on looping Please use speaker notes for additional information!
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
Chapter 5 Loops. Overview u Loop Statement Syntax  Loop Statement Structure: while, for, do-while u Count-Controlled Loops u Nested Loops u Loop Testing.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
Visual Basic Programming
Flow Control in Java. Controlling which instruction to execute next Sequential  Similar to walking, one step after another Branching  Similar to a fork.
1 Ch. 6 Iteration (Loops) Loops repeat a set of instructions Two types of loops: –Definite loops ( for ) perform instructions explicit number of times.
CS 100 Introduction to Computing Seminar October 7, 2015.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
2 Chapter 21 Understanding Structure Programming Logic and Design, Second Edition, Comprehensive 2.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Controlling Program Flow with Looping Structures
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
P ROGRAMMING L OGIC GWDA123 Sharon Kaitner, M.Ed. Winter 2015: Week 2.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
Chapter 6 Controlling Program Flow with Looping Structures.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Structured Programming The Basics
Programming Logic and Design Seventh Edition
Chapter 6: Loops.
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
Karel J Robot Chapter 6.
CS 115 Lecture 8 Structured Programming; for loops
Programming Logic and Design Eighth Edition
A Beginner’s Guide to Programming Logic, Introductory
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
Iteration with While You can say that again.
CPS120: Introduction to Computer Science
Program Flow CSCE 121 J. Michael Moore.
Structured Programming Taken from notes by Dr. Neil Moore
Do … Loop Until (condition is true)
CMPT 102 Introduction to Scientific Computer Programming
ICT Programming Lesson 3:
Flow of Control.
The structure of programming
More Loops Topics Counter-Controlled (Definite) Repetition
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
More Loops Topics Counter-Controlled (Definite) Repetition
CPS120: Introduction to Computer Science
More Loops Topics Counter-Controlled (Definite) Repetition
Presentation transcript:

Structured Programming The Basics

Control structures They control the order of execution What order statements will be done in, or whether they will be done at all (skipping) Different from data structures – which are ways to access data, to operate on it

Why do structured programming? It's easier to understand code written using structured programming Easier to test and debug code Easier to modify and maintain code Easier to work with other people to write large programs

4 Control Structures Sequence Selection Iteration Module

Guarantees for All Structures ONE Entrance ONE Exit

SEQUENCE Statement 1 Statement 2 Statement 3...

Guarantees for Sequences Will execute the steps in the order given Will not enter or leave sequence in mid- stream Will not skip steps

SELECTION(branch) IF Condition THEN Statement1 ELSE Statement2 Statements1 Statement Statements2 Condition... True False

Selection Guarantees Control always enters through the condition / question One branch or the other is executed, never both on one run MUST execute one branch or the other Processes in branches can be as large or small as you want Do not write Dead Code!

Dead Code

LOOP(repetition) Body Condition... False True WHILE Condition DO Statement1

Guarantees Will go through test / condition at top to get into loop ALL of body will be executed before test is done again Body will be repeated until test is answered differently (NO) Do not write Infinite Loops!

SUBPROGRAM(function) SUBPROGRAM1... SUBPROGRAM1 a meaningful collection of SEQUENCES, SELECTIONS, LOOPS, SUBPROGRAM calls

Module Flow of control