Download presentation
Presentation is loading. Please wait.
Published byAgatha Wells Modified over 8 years ago
1
Controlling Program Structures
2
Big Picture We are learning how to use structures to control the flow of our programs Last week we looked at If statements. This lesson we are going to look at Iteration with different kinds of loops.
3
Selection To make a choice. To do something in response to a test or condition In computing this is achieved using If statements
4
Iteration The process of doing something again and again. Either for a set number of times or until (while) a condition is met.
5
Indent/Indentation To set in or back from the margin, as the first line of a paragraph. See code below: word = "indentation" for letter in word: print (letter) print ("defines the loop")
6
Learning Objective The Objective of today’s lesson is to understand the use of iteration in a computer program.
7
Learning Outcomes LO1: know what iteration is in terms of computing and the structures that are used in python. (D-G) LO2: Apply knowledge to make the correct choice of structure to solve a given problem.(C) LO3: Create a working solution to a problem using the appropriate structure.(C+) (Grade above C will depend on quality of code and how well it is commented and documented)
8
For Example X = input(“please enter a number”) X = int(X) X = input(“please enter a number”) #get user input X = int(X) #change to integer #assign user input to variable X and cast X to integer data type X = int(input(“please enter a number”))
9
For / While Demo For Loop Used for fixed number of iterations For i in range (0,20): print(“Down”) print(“Up”) print(str(i)) Print(“Thank You”) While Loop Used to repeat an unknown number of times, until a condition is met bored = n While bored == n: print(“Down”) print(“Up”) bored = input (“Are you bored yet y/n”) Print(“thank You”)
10
Why indentation is vital word = "indentation" for letter in word: print (letter) print ("defines the loop") >>> i defines the loop n defines the loop d defines the loop e defines the loop n defines the loop t defines the loop a defines the loop t defines the loop i defines the loop o defines the loop n defines the loop >>> word = "indentation" for letter in word: print (letter) print ("defines the loop") >>> i n d e n t a t i o n defines the loop >>>
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.