Skip to content

Latest commit

 

History

History
43 lines (35 loc) · 1.06 KB

File metadata and controls

43 lines (35 loc) · 1.06 KB

Chapter 8. Loop Structure and Booleans

1. For loops

  • Strueture
for <var> in <sequences>:
    <body>

2. Indefinite loops

  • Structure
while <condition>: 
    <body>
  • Infinite loop

3. Common loop patterns

  • Interactive loops: allows the user to repeat certain portions of a program on demand.
  • Sential loops: continues to process data until reaching a special value that signals the end.
  • File loops
  • Nested loops

4. Computing with booleans

  • Boolean operator: '=='
<expr> and <expr>
<expr> or <expr>
  • Boolean algebra

5. Other common structure

  • Post-test loop: ex) input validation
  • Loop and a half: loop exit is actually in the middle of the loop body.
  • The logic of a loop is easily lost when there are multiple exits.
  • Error case: 'while response[O] == "y" or "Y":'
  • Python's Boolean operators are shortcircuit operators.

6. Example

  • Modal input: lock the user into a certain mode of interaction. <-> nonmodal(multimodal)

*** 이중 for 문 한 번에 break 깨기, is