Lesson 05: Iterations Class Chat: Attendance: Participation

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

While loops.
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:
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
New Mexico Computer Science For All More Looping in NetLogo Maureen Psaila-Dombrowski.
Fundamentals of Python: From First Programs Through Data Structures
Fundamentals of Python: First Programs
Programming Logic and Design Fifth Edition, Comprehensive
Computer Science 111 Fundamentals of Programming I The while Loop and Indefinite Loops.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Programming Logic and Design Sixth Edition Chapter 5 Looping.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 6 Looping.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
Pascal Programming Pascal Loops and Debugging. Pascal Programming Pascal Loops In our first brush with the while do loops, simple comparisons were used.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Controlling Program Flow with Looping Structures
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.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
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.
Follow up from lab See Magic8Ball.java Issues that you ran into.
CMSC201 Computer Science I for Majors Lecture 07 – While Loops
Lesson 06: Functions Class Participation: Class Chat:
Lesson 03: Variables and Types
Lesson 08: Files Class Participation: Class Chat: Attendance Code 
Lesson 07: Strings Class Chat: Attendance: Participation
Lesson 02: Introduction to Python
Lesson 04: Conditionals Topic: Introduction to Programming, Zybook Ch 3, P4E Ch 3. Slides on website.
Python: Control Structures
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.
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Chapter 5: Loops and Files.
Chapter 5: Repetition Structures
While Loops in Python.
Topics Introduction to Repetition Structures
Iterations Programming Condition Controlled Loops (WHILE Loop)
Learning About the Loop Structure (continued)
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.
Iteration with While You can say that again.
MSIS 655 Advanced Business Applications Programming
Lesson 04: Conditionals Class Chat: Attendance: Participation
Lesson 05: Iterations Topic: Introduction to Programming, Zybook Ch 4, P4E Ch 5. Slides on website.
Lesson 09: Lists Topic: Introduction to Programming, Zybook Ch 8, P4E Ch 8. Slides on website.
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
IST256 : Applications Programming for Information Systems
Lesson 06: Functions Class Chat: Attendance: Participation
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
Lesson 03: Variables and Types
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
Lesson 08: Files Class Chat: Attendance: Participation
Lesson 10: Dictionaries Class Chat: Attendance: Participation
CHAPTER 6: Control Flow Tools (for and while loops)
Another Example Problem
Lesson 02: Introduction to Python
Learning Plan 4 Looping.
While Loops in Python.
Lesson 07: Strings Class Chat: Attendance: Participation
Iteration – While Loops
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

Lesson 05: Iterations Class Chat: Attendance: Participation Link: In Gitter.im | Code: ???? Class Chat: https://gitter.im/IST256/Fudge Participation http://ist256.participoll.com/

Questions? Ask in Our Course Chat! Agenda Make our code execute in a non linear fashion. Definite loops (for loops) and iterators. Indefinite looping, infinite loops, and the break and continue statements How to build complex loops easily. You’ve Read: Zybook Ch4 P4E Ch5 https://gitter.im/IST256/Fudge Questions? Ask in Our Course Chat!

Connect Activity Select the line number where the increment occurs: 4 5 6 7 A B C D

Increment and Decrement Increment means to add a value to a variable. X = X + 1 Decrement means to subtract a value from a variable. X = X - 1 These are common patterns in iteration statements which you will see today.

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 or Iteration Variables. Our goal is to make the Test condition False so that the loop stops. This is accomplished through changing the loop control variable.

Watch Me Code 1 Say My Name: This program will say you name a number of times. This is an example of a Definite loop because the number of iterations are pre-determined.

For Loop The For Loop iterates over a python list, string, or range of numbers. It is the preferred statement for Definite loops, where the number of iterations are pre-determined. Definite loops do not require an exit condition. The for loop uses an iterator to select each item from the list or range and take action in the loop body. The range() function is useful for getting an iterator.

Watch Me Code 2 Say My Name: Range() function Refactored as a For Loop.

Check Yourself: For Range What is the value of k on line 4? 2 3 6 10 j 1 2 ? k A B C D

Watch Me Code 3 Count the "i"'s Definite Loop

Indefinite,Infinite Loops and Break The Indefinite Loop has no pre-determined exit condition. There are no guarantees an indefinite loop will end, as it is typically based on user input. Infinite Loops are loops which can never reach their exit condition. These should be avoided at all costs. The break statement is used to exit a loop immediately.It is often used to force an exit condition in the body of the loop.

Indefinite Loops The Easy Way Determine the code to repeat Determine the loop control variables & exit conditions Write exit conditions as if statements with break Wrap the code in a while True: loop!

Watch Me Code 4 Guess My Name: This program will execute until you guess my name. Uses the indefinite loop approach

End-To-End Example 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.

Conclusion Activity "One Important Thing" Share one important thing you learned in class today on Gitter.im!!!