Control Structures CPS120: Introduction to Computer Science Lecture 5.

Slides:



Advertisements
Similar presentations
Chapter 4: Control Structures I (Selection)
Advertisements

ALGORITHMS - PART 2 CONDITIONAL BRANCH CONTROL STRUCTURE
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Understanding the Three Basic Structures
Lesson 5 - Decision Structure By: Dan Lunney
Introduction to Programming
زبانهای برنامه سازی برنامه سازی پیشرفته ارائه دهنده دکتر سيد امين حسيني E.mail: Home page:
CS0004: Introduction to Programming Repetition – Do Loops.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
Program Design and Development
Chapter 2: Design of Algorithms
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
Algorithm. An algorithm is a procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed.
CSC103: Introduction to Computer and Programming
Programming Languages CPS120: Introduction to Computer Science Lecture 5.
Flow of Control. 2 Control Structures Control structure: An instruction that determines the order in which other instructions in a program are executed.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
Jaeki Song ISQS6337 JAVA Lecture 04 Control Structure - Selection, and Repetition -
CPS120: Introduction to Computer Science Decision Making in Programs.
CPS120 Introduction to Computer Science Iteration (Looping)
CPS120 Introduction to Computer Programming The Programming Process.
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
Visual Basic Programming
PROBLEM SOLVING WITH LOOPS Chapter 7. Concept of Repetition Structure Logic It is a computer task, that is used for Repeating a series of instructions.
Lecture 2 Numerical Methods for Engineering MECN 3500 Department of Mechanical Engineering Inter American University of Puerto Rico Bayamon Campus Dr.
ITEC113 Algorithms and Programming Techniques
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
1 CSCI N201 Programming Concepts and Database 9 – Loops Lingma Acheson Department of Computer and Information Science, IUPUI.
The world of Constructs Control Structures. The three Structures Sequence Selection Loop Entry Exit.
Algorithm Design.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Control Structures RepetitionorIterationorLooping Part I.
Chapter 5: Control Structures I (Selection). Objectives In this chapter you will: Learn about control structures Examine relational and logical operators.
CPS120 Introduction to Computer Science Iteration (Looping)
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
Prof. Ken Regis Institute for Computer Engineering Florida State University Oktober 2002Prof. Ken Regis - FIT 1-11.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
CPS120: Introduction to Computer Science Decision Making in Programs.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
CPS120: Introduction to Computer Science Decision Making in Programs.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
CPS120: Introduction to Computer Science Session 5.
1 CSC103: Introduction to Computer and Programming Lecture No 9.
Fundamentals of Algorithms MCS - 2 Lecture # 3. Representation of Algorithms.
Pseudocode. Algorithm A procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed.
1 Structured Programming Arab Academy for Science and Technology CC112 Dr. Sherif Mohamed Tawfik The Course.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
CNG 140 C Programming (Lecture set 3)
REPETITION CONTROL STRUCTURE
Sequence, Selection, Iteration The IF Statement
PROGRAM CONTROL STRUCTURE
CPS120: Introduction to Computer Science
Introduction to pseudocode
Coding Concepts (Basics)
Faculty of Computer Science & Information System
Computer Science Core Concepts
ICT Programming Lesson 3:
Flow of Control.
CPS120: Introduction to Computer Science
Presentation transcript:

Control Structures CPS120: Introduction to Computer Science Lecture 5

What Can a Program Do? A program can only instruct a computer to: –Read Input –Sequence –Calculate –Store data –Compare and branch –Iterate or Loop –Write Output

Fundamental Programming Concepts Assignment of values to a variable Iteration (Looping) –Over a set of set of statements –With respect to a logical expressions (conditions) Delegation of sub-tasks to functions / procedures

The Structure Theorem The Structure Theorem states that any algorithm can be built from three basic control structures. One-after-another (Sequence) Decision-making (Selection) –Making choices between 2 or more alternatives Repetition (Iteration) –Concerned with repetitive tasks (and the termination conditions of loops)

C++ Control Structures 1."Sequence statements" are imperatives 2."Selection" is the "if then else" statement –AND, OR, NOT and parentheses ( ) can be used for compound conditions 3."Iteration" is satisfied by a number of statements –"while" –" do " – "for" 4.The case-type statement is satisfied by the "switch" statement. –CASE statements are used for most non-trivial selection decisions

Sequence Control Structures Sequence control structures direct the order of program instructions. The fact that one instruction follows another—in sequence—establishes the control and order of operations.

Calculate A program can instruct a computer to perform mathematical operations. Add 1 to Counter

Store A program will often instruct a computer to store intermediate results. Place 1 in Counter

Compare and Branch A program can instruct a computer to compare two items and do something based on a match or mismatch which, in turn, redirect the sequence of programming instructions. –There are two forms: –IF-THEN –IF-THEN-ELSE

IF-THEN Test condition p falsetrue Entry Exit True statement a

IF-THEN-ELSE falsetrue Entry Exit Test condition p “true” statement a “false” statement a

Iterate A program loop is a form of iteration. A computer can be instructed to repeat instructions under certain conditions.

Iteration Control Structures Iteration control structures are looping mechanisms. Loops repeat an activity until stopped. The location of the stopping mechanism determines how the loop will work: Leading decisions Trailing decisions

Leading Decisions If the stop is at the beginning of the iteration, then the control is called a leading decision. The command DO WHILE performs the iteration and places the stop at the beginning.

DO WHILE Loop No Yes Entry Exit Test condition p Loop statement a

Trailing Decisions If the stop is at the end of the iteration, the control mechanism is called a trailing decision. The command DO UNTIL performs the iteration and puts the stop at the end of the loop.

DO UNTIL Loop Loop statement a NoYes Entry Test condition p Exit