{"assignment":{"_schema_version":2,"course_id":37,"date_created":"2022-06-28T19:00:00+00:00","date_modified":"2024-10-30T14:52:39.359830+00:00","extra_instructor_files":"","extra_starting_files":"","forked_id":null,"forked_version":null,"hidden":false,"id":1128,"instructions":"## While Loops\n\n```python while-loop-example\ncommand = input(\"Type EXIT to stop.\")\nwhile command != \"EXIT\":\n    command = input(\"Type EXIT to stop.\")\nprint(\"You typed EXIT\")\n```\n\nWe previously learned how `for` loops can iterate through a list of elements, a string, or a file.\nSince we always know how long those values are, we can iterate safely in these forms of *finite* iteration.\nBut what about times when we have to loop an arbitrary number of times?\nFor example, if we need to repeatedly ask the user to enter input, until the user successfully enters a number and not something invalid.\nFor this, programmers have the `while` loop, which is a more powerful and therefore more dangerous form of iteration.\nIt's sort of like an `if` statement, except instead of continuing on to the rest of the program, while the condition is `True` the body will keep repeatedly executing.\nAnything that a `for` loop can do, a `while` loop can do too.\nHowever, a `while` loop can do some things that a `for` loop cannot easily do.\nBe careful, though, the programmer must be very careful to avoid causing an infinite loop and letting the program run forever!\n\n## While Loop Patterns\n\n* Numeric While\n* List While\n* Read-Evaluate-Print-Loop\n* User Input Loop\n* Random Looping\n* Main Game/Server Loop\n\nLike `for` loops, we introduce some patterns for `while` loops that can help guide your coding.\nHowever, these patterns are much looser than the patterns we cover with `for` loops, and are less generalizable.\nYou can think of them as more like examples, or loose guidelines at best.\nIn general, you should try to first think if a given problem can be solved with a `for` loop before you try to jump to a `while` loop.\nYou would not immediately leap to a chainsaw when a pair of scissors would do.\nBut of course, sometimes you need a bit of extra chopping power and a chainsaw becomes needed.\nIn the same way, when you need a `while` loop, nothing else will suffice.\nThese patterns can help you see opportunities for using this interesting control structure.\n\n## Plotting\n\nYou'll make graphs! Histograms, line plots, and scatter plots.","ip_ranges":"","name":"10) Primer","on_change":"","on_eval":"","on_run":"","owner_id":1,"owner_id__email":"acbart@udel.edu","points":1,"public":true,"reviewed":false,"sample_submissions":[],"settings":"{\n  \"header\": \"While and Plotting\",\n  \"youtube\": {\n    \"Bart\": \"9-wR7VDj-qg\",\n    \"Amy\": \"TgUEHWS1SYY\"\n  },\n  \"video\": {\n    \"Bart\": \"https://blockpy.cis.udel.edu/videos/bakery_time_primer-Bart.mp4\",\n    \"Amy\": \"https://blockpy.cis.udel.edu/videos/bakery_time_primer-Amy.mp4\"\n  },\n  \"summary\": \"\",\n  \"small_layout\": true\n}","starting_code":"","subordinate":false,"tags":[],"type":"reading","url":"bakery_time_primer_read","version":8},"ip":"216.73.216.157","submission":{"_schema_version":3,"assignment_id":1128,"assignment_version":8,"attempts":0,"code":"","correct":false,"course_id":37,"date_created":"2026-05-20T12:51:55.040523+00:00","date_due":"","date_graded":"","date_locked":"","date_modified":"2026-05-20T12:51:55.040523+00:00","date_started":"","date_submitted":"","endpoint":"","extra_files":"","feedback":"","grading_status":"NotReady","id":2036885,"score":0.0,"submission_status":"Started","time_limit":"","url":"submission_url-02f51978-2e07-4444-a4b5-c9919aac759e","user_id":2044663,"user_id__email":"","version":0},"success":true}
