mastery objective n.
Skip this Video
Download Presentation
Mastery Objective:

Loading in 2 Seconds...

play fullscreen
1 / 15

Mastery Objective: - PowerPoint PPT Presentation

  • Uploaded on

Mastery Objective:. Students will understand how to use while loops in computer programming. Agenda.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Mastery Objective:' - ganya

Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
mastery objective

Mastery Objective:

Students will understand how to use while loops in computer programming

  • If-else and if-elif-else assignment due tomorrow (Wednesday) by the end of class with no scheduled in class time. If you haven’t finished the assignment, plan to stay after or come in early to finish the assignment.
  • Notes: While loops
  • Programming assignments
while loops
While loops

Basic principle:

  • While something is true, repeat something

Basic structure:

while response != “Because.”:

response = raw_input(“Why? “)

similarities and differences between if and while structure
Similarities and differences between if and while structure
  • In both structures, if the condition is true, the block is executed.
  • What is different: In the while structure, the block is executed until it is false.
sentry variable
Sentry Variable
  • Often, sentry variables control the while loop
  • response variable in example code

while response != “Because.”:

response = raw_input(“Why? “)

  • Must be intialized prior to use, usually right before while loop. Usually initialized to empty variable

response = “ “


response = “”

while response !=“No”:

response = “raw_input(“Try again!”):

print “All done!”

infinite loop
Infinite Loop
  • Loop that never ends.
  • Example

counter = 0

while counter <=10

print counter

Forgot to increase counter variable

Counter +=1

setting values as true or false
Setting values as true or false

When using numbers: 0 is false other numbers are true

if money:

print “Thank you!”


print “I am sorry there are no seats available.”

intentional infinity loops
Intentional Infinity loops
  • There is a place for infinite loops

Count = 0

While Ture:

count +=1

if count >10:

break (breaks loop)

if count ==5;

continue (jump back to top of loop)

print count

break and continue
Break and Continue
  • Used in any type of loop
  • Should be used sparingly
using compound conditions
Using compound conditions
  • Uses logical operators
not logical operator example
not Logical Operator Example

username = “ “

while not username:

username = raw_input(“Username: “)

Loop continues to ask for a username until the user enters something

and logical operator
And Logical Operator

elif username == “S. Meier” and password ==“civilization”:

or logical operator example
Or Logical operator example

elif username==“guest” or password ==“guest”:

print “Welcome, guest.”