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.

Slides:



Advertisements
Similar presentations
Looping Structures: Do Loops
Advertisements

How SAS implements structured programming constructs
Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
Lecture 12 – Loops – while loops COMPSCI 1 1 Principles of Programming.
Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
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.
Intro to Java while loops pseudocode. 1 A “Loop” A simple but powerful mechanism for “making lots of things happen!” Performs a statement (or block) over.
Chapter 61 Flags A flag is a variable that keeps track of whether a certain situation has occurred. The data type most suited to flags is Boolean.
Loops are MATLAB constructs that permit us to execute a sequence of statements more than once. There are two basic forms of loop constructs: i. while.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
MATLAB® While Loops.
Control Structures FOR Statement Looping.
Python Repetition. We use repetition to prevent typing the same code out many times and to make our code more efficient. FOR is used when you know how.
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,
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Coding Design Tools Rachel Gauci. Task: Counting On Create a program that will print out a sequence of numbers from "1" to a "number entered”. Decision’s.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
Chapter 3: Branching and Program Flow CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
CS 100 Introduction to Computing Seminar October 7, 2015.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Using Loops. Goals Understand how to create while loops in JavaScript. Understand how to create do/while loops in JavaScript. Understand how to create.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Structured Programming The Basics. Control structures They control the order of execution What order statements will be done in, or whether they will.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
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.
These Guys? Wait, What? Really?  Branching is a fundamental part of programming  It means taking an action based on decision  The decision is dependent.
GCSE Computing#BristolMet Session Objectives #23 MUST understand what is meant by the programming term iteration SHOULD describe methods of looping used.
Control Structures If Else Statement. S E S Q C E N U …consecutive steps (or groups of steps) processed one after another in the order that they arise.
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.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
5a – While Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
 See pages 65 – 67 in your book  While loops are all around us ◦ Shampoo  Rinse, Lather, Repeat  While (Condition Is True) : ◦ Execute a block of.
Controlling Program Structures. Big Picture We are learning how to use structures to control the flow of our programs Last week we looked at If statements.
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.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
More about Iteration Victor Norman CS104. Reading Quiz.
Lesson 05: Iterations Class Chat: Attendance: Participation
If, else, elif.
CiS 260: App Dev I Chapter 4: Control Structures II.
( Iteration / Repetition / Looping )
Web Programming– UFCFB Lecture 16
Iterations Programming Condition Controlled Loops (WHILE Loop)
While Loops (Iteration 2)
Chapter 5 Structures.
For Loops October 12, 2017.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Loop Control Structure.
IPC144 Introduction to Programming Using C Week 3 – Lesson 2
IST256 : Applications Programming for Information Systems
More Looping Structures
Control Structures Part 1
Loops Prof.Gaikwad Varsha P. Information Technology Dept.
Alternate Version of STARTING OUT WITH C++ 4th Edition
For Loops (Iteration 1) Programming Guides.
A LESSON IN LOOPING What is a loop?
CHAPTER 6: Control Flow Tools (for and while loops)
PROGRAM FLOWCHART Iteration Statements.
Learning Plan 4 Looping.
More Looping Structures
Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times.
Starter Look at the hand-out.
Week 3 – Repetition (ctd.)
GCSE Computing.
GCSE Computing.
Presentation transcript:

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. …or Iteration

Sometimes we want to repeat a bit of code many times. We use loops to achieve this! For example, if you wanted to output the same statement 3 times, we would use a FOR loop. This is because we know the number of iterations. RULE: use a FOR loop if the number of iterations is known. What if we don’t know the number of iterations? For example, iterate until the user enters a specific value…

Condition ? Execute code block If condition is true If condition is false WHILE Loop Like if statements, while loops evaluate whether a condition is true or false! The block is evaluated (iterated) until the condition becomes false.

Looping mechanisms in python… In Python, there are 2 looping mechanisms… FOR LOOP WHILE LOOP LOOPS for a specified number of times! For example, output HELLO WORLD 3 times LOOPS for a an unknown number of times! For example, output HELLO WORLD ? times until user types quit.

>>>password = (‘dalriada‘) guess = input(‘Please enter password: ‘) while guess != password: print(‘Access denied') guess = input(‘Please try again’) print(‘Access granted’) Syntax while : Example, prompt the user to guess the password (dalriada)

What will be output here?

>>>number =1 while number < 5: print(number*number) number = number + 1 What will be output here?

>>>while x < 5: print(‘Hello’) What will be output here?