IST256 : Applications Programming for Information Systems

Slides:



Advertisements
Similar presentations
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Advertisements

Chapter 7 - Iteration. Chapter Goals Program repitiation statements – or loops – with the for, while, and do-while statements Program repitiation statements.
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Objectives In this chapter, you will learn about:
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.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Fundamentals of Python: From First Programs Through Data Structures
Fundamentals of Python: First Programs
Chapter 2 Control. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. Repetition, quick overview.
Control Structures FOR Statement Looping.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved For Loops October 16, 2013 Slides by Evan Gallagher.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
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.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
GAME102 - INTRO WHILE LOOPS G. MacKay. Fundamental Control Structures  STRAIGHT LINE  CONDITIONAL  LOOPS.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Iteration. Iteration: Review  If you wanted to display all the numbers from 1 to 1000, you wouldn’t want to do this, would you? Start display 1 display.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Fundamental Programming Fundamental Programming More on Repetition.
Lecture 7: Menus and getting input. switch Multiple-selection Statement switch Useful when a variable or expression is tested for all the values it can.
9. ITERATIONS AND LOOP STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
Structured Programming Structured Programming is writing a program in terms of only 3 basic control structures: sequence selection repetition We have already.
Testing Programs with Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
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.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2016, Fred McClurg, All Rights.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Chapter 5: Looping. Using the while Loop Loop – A structure that allows repeated execution of a block of statements Loop body – A block of statements.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
More about Iteration Victor Norman CS104. Reading Quiz.
CMSC201 Computer Science I for Majors Lecture 07 – While Loops
Week of 12/12/16 Test Review.
Control Structures II Chapter 3
CS161 Introduction to Computer Science
Lesson 05: Iterations Class Chat: Attendance: Participation
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.
While Loops in Python.
Learning About the Loop Structure (continued)
Intro to Computer Science CS1510 Dr. Sarah Diesburg
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Iteration with While You can say that again.
TOPIC 4: REPETITION CONTROL STRUCTURE
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Lesson 05: Iterations Topic: Introduction to Programming, Zybook Ch 4, P4E Ch 5. Slides on website.
Lecture Notes – Week 3 Lecture-2
Lesson 09: Lists Topic: Introduction to Programming, Zybook Ch 8, P4E Ch 8. Slides on website.
Repetition Structures
IPC144 Introduction to Programming Using C Week 3 – Lesson 2
Do … Loop Until (condition is true)
Lesson 09: Lists Class Chat: Attendance: Participation
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 6: Repetition Statements
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
CSC115 Introduction to Computer Programming
Another Example Problem
PROGRAM FLOWCHART Iteration Statements.
IST256 : Applications Programming for Information Systems
Python While Loops.
While Loops in Python.
IST256 : Applications Programming for Information Systems
IST256 : Applications Programming for Information Systems
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
Iteration – While Loops
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
IST256 : Applications Programming for Information Systems
Presentation transcript:

IST256 : Applications Programming for Information Systems Loops: Iterating over Code

Agenda Connection Activity Teaching: Practice Activity While Loops For Loops Practice Activity Guess a Number

Connect Activity Full-Contact Kahoot!: Let’s prepare for the quiz with a game of Kahoot! Top 3 Get a Prize! https://play.kahoot.it/#/?quizId=7a1ac0ce-d02c-45b6-84e7-b4680b5aa1e6

Anatomy of a loop A Loop is a sequence of code that repeats as long as a Boolean expression is True. The sequence of code that repeats is known as the Body. The Boolean expression which is tested is known as the Test Condition or Exit Condition. Variables which are part of the Test condition are called Loop Control Variables. If the Test condition value never changes, the loop will continue forever. This is called an Infinite Loop. This is why loop control variables should change value in the loop body.

Quick: Watch Me Code Let’s Count to 10. Or 50. Or 100.

Check Yourself: 90 Second Challenge X = “Python” Y = [“Programming”, “Is”, “Fun”] What is: X[3] ? Y[1] ? Y[0][1] ? What is the Test Condition? What is/are the loop control variable(s)? Which line numbers are in the loop body? What is the first value to print? How many times does this loop iterate?

Watch Me Code Password Prompt Example Infinite loops The Break Statement

For Loop The For Loop iterates over a python list or range of numbers. The for loop uses an iterator to select each item from the list or range and take action in the loop body.

Watch Me Code For Loop Example Iterate over a Range Iterate over a list

Check Yourself: 90 Second Challenge Match the Definition… To its term. Add one to a variable Subtract one from a variable Test condition is never false Exit the loop Loop a fixed number of times Break Increment Infinite loop Decrement For

Help me Code Password Program: 5 attempts for the password On correct password, print: “Access Granted”, then end the program On incorrect password “Invalid Password Attempt #” and give the user another try After 5 attempts, print “You are locked out”. Then end the program.

Now You Code Guess a number guessing game between 1 and 100: Use random.randint(1,100) to get a number. Allow a user guess the number If correct say so! If guess too high, say “Lower” If guess too low, say “Higher” After they guess correctly, print number of guesses it took to find the correct number.