Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!

Slides:



Advertisements
Similar presentations
Algorithms 10 IST – Topic 6.
Advertisements

CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Lesson 5 - Decision Structure By: Dan Lunney
CS0004: Introduction to Programming Repetition – Do Loops.
CHAPTER 5: LOOP STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
Chapter 5: Control Structures II (Repetition)
Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski.
UNIT II Decision Making And Branching Decision Making And Looping
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
CPS120 Introduction to Computer Science Iteration (Looping)
CPS120 Introduction to Computer Programming The Programming Process.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
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,
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
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 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
Control Structures CPS120: Introduction to Computer Science Lecture 5.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
CPS120 Introduction to Computer Science Iteration (Looping)
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
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.
Structured Programming The Basics. Control structures They control the order of execution What order statements will be done in, or whether they will.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
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.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional,
PYTHON WHILE LOOPS. What you know While something is true, repeat your action(s) Example: While you are not facing a wall, walk forward While you are.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
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.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
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.
Think What will be the output?
Ch 7: JavaScript Control Statements I.
Programming Fundamentals
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Loop Control Structure.
CPS120: Introduction to Computer Science
Outline Altering flow of control Boolean expressions
Iteration: Beyond the Basic PERFORM
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
3 Control Statements:.
Introduction to Problem Solving and Control Statements
Three Special Structures – Case, Do While, and Do Until
Computer Science Core Concepts
ICT Programming Lesson 3:
ICT Gaming Lesson 2.
Program Flow.
The structure of programming
FLUENCY WITH INFORMATION TECNOLOGY
The structure of programming
Python While Loops.
Thinking procedurally
How to allow the program to know when to stop a loop.
Presentation transcript:

Flow Control in Imperative Languages

Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!

Flow Control in Imperative Languages Introduction What is an Imperative Language and Flow Control? An imperative language is one which is has a set of statements to determine how to reach a goal. The FLOW of these statements is CONTROLLED by 3 different structures. - Sequencing - Selection - Iteration Learning Objectives: (g) understand and use sequence in an algorithm (h) understand and use selection in an algorithm (IF and CASE statements) (i) understand and use iteration in an algorithm (FOR, WHILE and REPEAT loops).

Flow Control in Imperative Languages The 3 Constructs of Imperative Languages Learning Objectives: (g) understand and use sequence in an algorithm (h) understand and use selection in an algorithm (IF and CASE statements) (i) understand and use iteration in an algorithm (FOR, WHILE and REPEAT loops). And Then This Then This Do This While X = 2 Keep Looping! 1.Sequencing Performing one instruction after another 3. Iterations The program repeating, looping infinitely or for a set number of times. 2. Selection The program making decisions

Flow Control in Imperative Languages Sequencing A sequence is a control structure where the computer executes every instruction in the order in which they are written. Here is an example of sequencing in an algorithm: Each line is executed before moving on to the next. Learning Objectives: (g) understand and use sequence in an algorithm (h) understand and use selection in an algorithm (IF and CASE statements) (i) understand and use iteration in an algorithm (FOR, WHILE and REPEAT loops). And Then This Then This Do This 1.Sequencing Performing one instruction after another

Flow Control in Imperative Languages Selection – Conditional Operations Often we want programs to act differently when certain conditions occur. Selection is a control structure which contains instructions that DO NOT have to be executed in sequence (non-sequential). There are two main types of selection. - Selection of 2 possible pathways - IF-THEN-ELSE statements - Multiple Selections - CASE statements (uses the keyword ELIF in Python) Learning Objectives: (g) understand and use sequence in an algorithm (h) understand and use selection in an algorithm (IF and CASE statements) (i) understand and use iteration in an algorithm (FOR, WHILE and REPEAT loops). 2. Selection The program making decisions

Flow Control in Imperative Languages Learning Objectives: (g) understand and use sequence in an algorithm (h) understand and use selection in an algorithm (IF and CASE statements) (i) understand and use iteration in an algorithm (FOR, WHILE and REPEAT loops). 2. Selection The program making decisions Selection of 2 – IF-THEN-ELSE STATEMENTS These are used to see if a certain condition is true or false. IF the condition is true THEN a certain set of instructions will be executed. ELSE (condition is false) then a different set of instructions will be executed.

Flow Control in Imperative Languages Learning Objectives: (g) understand and use sequence in an algorithm (h) understand and use selection in an algorithm (IF and CASE statements) (i) understand and use iteration in an algorithm (FOR, WHILE and REPEAT loops). 2. Selection The program making decisions Multiple Selection – CASE STATEMENTS (ELIF in Python) These are used to run one of many possible instructions based on various conditions It makes use of CASE OF and ENDCASE to select one instruction from a set of instructions, depending on the value of a variable. It does the same job as multiple (nested) IF-ELSE statements but is more efficient.

Flow Control in Imperative Languages Iterations – Iterative Operations Often we want programs to repeat a process until a condition is met. Iteration is the Control Structure which allows this to occur. There are two ways to get code to loop: 1. Counting a set number of loops 2. Setting a condition which must be met for the loop to end. Learning Objectives: (g) understand and use sequence in an algorithm (h) understand and use selection in an algorithm (IF and CASE statements) (i) understand and use iteration in an algorithm (FOR, WHILE and REPEAT loops). 3. Iterations The program repeating, looping infinitely or for a set number of times.

Flow Control in Imperative Languages Counting a set number of loops If we know how many times we want a loop to run for we use a FOR loop. This uses a counter with FOR, TO and NEXT to repeat a block of code a set number of times. The counter can go up or down in different steps. Learning Objectives: (g) understand and use sequence in an algorithm (h) understand and use selection in an algorithm (IF and CASE statements) (i) understand and use iteration in an algorithm (FOR, WHILE and REPEAT loops). 3. Iterations The program repeating, looping infinitely or for a set number of times.

Flow Control in Imperative Languages Setting a condition (which must be met for the loop to end) If we do not know how many times we want a loop to run for and instead want the loop to repeat until a certain condition is met we will use a WHILE loop. This states that WHILE a certain condition is true, the code is continue repeating. The check occurs at the start of each loop. The instructions in the loop will be ignored if the WHILE condition is false. Learning Objectives: (g) understand and use sequence in an algorithm (h) understand and use selection in an algorithm (IF and CASE statements) (i) understand and use iteration in an algorithm (FOR, WHILE and REPEAT loops). 3. Iterations The program repeating, looping infinitely or for a set number of times.

Flow Control in Imperative Languages Setting a condition (which must be met for the loop to end) In most programming languages (but not python) there is also a REPEAT UNTIL loop which will repeat a block of code until a condition occurs. The check is always carried out at the end of the loop. Unlike the WHILE loop, the instructions will always be carried out at least once. Learning Objectives: (g) understand and use sequence in an algorithm (h) understand and use selection in an algorithm (IF and CASE statements) (i) understand and use iteration in an algorithm (FOR, WHILE and REPEAT loops). 3. Iterations The program repeating, looping infinitely or for a set number of times.