1 / 12

Lab #2-4 Follow-Up: Further into Python

Lab #2-4 Follow-Up: Further into Python. Part 2: Loops. Repetition: The Essence of Computing (Revisited). Recall our assembly-lanuage program for repeated addition: We would like a more abstract / expressive way of doing repetitions!. LOAD A R1 LOAD B R2 LOAD ZERO R3

penha
Download Presentation

Lab #2-4 Follow-Up: Further into Python

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab #2-4 Follow-Up:Further into Python

  2. Part 2: Loops

  3. Repetition: The Essence of Computing (Revisited) • Recall our assembly-lanuage program for repeated addition: • We would like a more abstract / expressive way of doing repetitions! LOAD A R1 LOAD B R2 LOAD ZERO R3 ADD R2 R3 DECR R1 JNZ R1 103 STOR C R3

  4. for loops: When you know the # of reps for i in range(10): dance()

  5. for loops: When you know the # of reps for i in range(10): dance() Like function

  6. Can have more than one instruction in a loop for i in range(10): dance() speak('Oops I did it again!')

  7. range creates a list of values to “loop over” for i in range(10): print(i)

  8. range creates a list of values to “loop over” for i in range(10): print(i) 0 1 2 3 4 5 6 7 8 9 Output

  9. range creates a list of values to “loop over” for i in range(10): print(i) 0 1 2 3 4 5 6 7 8 9 Output Google dijkstra archive zero for why!

  10. forwithout range for name in ['Chris', 'Hannah', 'Will']: print(name) An explicit list

  11. while: when you don't know how many reps # Get current time in seconds startTime = currentTime() # Keep moving for 30 seconds while (currentTime() – startTime) < 30: keepMoving()

  12. while: when you don't know how many reps # Get current time in seconds startTime = currentTime() # Keep moving for 30 seconds while (currentTime() – startTime) < 30: keepMoving() A Booleancondition: either False or True

More Related