Structured Programming The Basics

Slides:



Advertisements
Similar presentations
Automating Software Module Testing for FAA Certification Usha Santhanam The Boeing Company.
Advertisements

While loops.
CS0004: Introduction to Programming Repetition – Do Loops.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
An Object-Oriented Approach to Programming Logic and Design Chapter 6 Looping.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
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 5: Control Structures II (Repetition)
CHAPTER 5: CONTROL STRUCTURES II INSTRUCTOR: MOHAMMAD MOJADDAM.
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.
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,
Programming Logic and Design Fourth Edition, Comprehensive Chapter 6 Looping.
Chapter 5 Control Structure (Repetition). Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct.
Chapter 5: Control Structures II (Repetition). Objectives In this chapter, you will: – Learn about repetition (looping) control structures – Learn how.
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.
Visual Basic Programming
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Programming in C++ Dale/Weems/Headington Chapter 1 Overview of Programming and Problem Solving.
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?
Structured Programming The Basics. Control structures They control the order of execution What order statements will be done in, or whether they will.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
Controlling Program Flow with Looping Structures
1 Overview of Programming Principles of Computers.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
C++ for Engineers and Scientists, Second Edition 1 Problem Solution and Software Development Software development procedure: method for solving problems.
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!
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 5: Control Structures II (Repetition)
1 Structured Programming Arab Academy for Science and Technology CC112 Dr. Sherif Mohamed Tawfik The Course.
Chapter 6 Controlling Program Flow with Looping Structures.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 4 Simple Flow of Control.
Programming Logic and Design Seventh Edition
Chapter 6: Loops.
REPETITION CONTROL STRUCTURE
The switch Statement, and Introduction to Looping
Programming Logic and Design Fourth Edition, Comprehensive
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
Control Structures II (Repetition)
Java Programming: Guided Learning with Early Objects
Structured Programming; for loops Taken from notes by Dr. Neil Moore
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
A Beginner’s Guide to Programming Logic, Introductory
Control Structures - Repetition
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Iteration with While You can say that again.
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Structured Programming Taken from notes by Dr. Neil Moore
CMPT 102 Introduction to Scientific Computer Programming
Chapter 6: Repetition Statements
ICT Programming Lesson 3:
Creating Computer Programs
Flow of Control.
FLUENCY WITH INFORMATION TECNOLOGY
More Loops Topics Counter-Controlled (Definite) Repetition
Chapter 4: Repetition Structures: Looping
Repetition Statements (Loops) - 2
Iteration (Loops) Loops repeat a set of instructions
More Loops Topics Counter-Controlled (Definite) Repetition
Creating Computer Programs
More Loops Topics Counter-Controlled (Definite) Repetition
Presentation transcript:

Structured Programming The Basics

Structured Programming Early programmers had to learn to program ad hoc – try things and see if they worked Early software engineers studied software projects to see why some succeeded and some failed They found patterns of programming that usually give good results when followed These are the rules of structured programming

Control Structures and Data Structures Control structures and data structures are the main components of any program Data structures allow you to access your data Simplest is a literal constant like 5 Variables are simple data structures – have a name, a value, a type, a location (address) in RAM Lists, files, graphics objects are more complex data structures

Control structures They control the order of execution What order statements will be done in, or whether they will be done at all (whether they are skipped or not) Different from data structures

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 True Statements1 Statement Condition . . . Statements2 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) WHILE Condition DO Statement1 False . . . Condition True Body

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! (usually a logic error in the controlling condition at the top)

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

Module Flow of control