1 / 11

CS111 Intro to Programming

CS111 Intro to Programming. Day 11: Looping. Learning Objectives. Identify code blocks based upon their indentation. Identify the components of a loop Demonstrate loop functionality by adding repeating sound to a composition. Loops. Déjà vu - Didn’t I already do this?.

kroll
Télécharger la présentation

CS111 Intro to Programming

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. CS111 Intro to Programming Day 11: Looping

  2. Learning Objectives • Identify code blocks based upon their indentation. • Identify the components of a loop • Demonstrate loop functionality by adding repeating sound to a composition

  3. Loops

  4. Déjà vu - Didn’t I already do this? Computers executes commands in a particular order called the control flow. If we want to duplicate an action over and over again, we could copy the statements as many times as we need… OR…. we could use a loop! A loop instructs the computer to execute a section of code repeatedly, creating more efficient code.

  5. Loop components Python provides several types of loops and in Chapter 12 we learn about the for-loop. For-loop Components: • Loop counter (variable) • Range ( values assigned to loop counter variable each time through the loop (iteration) ) • Loop body (code to execute repeatedly)

  6. Loop components Loop Counter is just a variable that is set to a new value with each step (iteration) through the loop.

  7. Loop components Range is function that returns a set of values over the specified range. The values range from the first value (inclusive) to the second value (exclusive).

  8. Loop components Loop Body is the code statements to repeat with each iteration of the loop. Statements must be indented to be included in the loop body.

  9. Loop Example

  10. More Cowbell! The music business can be brutal… Sometimes you just need more cowbell! Saturday Night Live Skit

  11. MiniTask

More Related