---
# System prepended metadata

title: Functions and Iterations

---

# Functions and Iterations
## Functions
**Dead Code** - code that execution can never reach
**Incremental development** - adding and testing only a small amount of code a time to avoid long debugging sessions
**Composition:**
```python=
def circle_area(xc, yc, xp, yp):
    return area(distance(xc, yc, xp, yp))
```
**Boolean Functions:**
```python=
def is_divisible(x,y):
    return x % y == 0
```
**Checking for types**: 
```python=
if isinstance(var, type):
    # ...
```
**Guardian** - pattern where conditionals protect code that follows from values that might cause an error.

**Scaffolding** - code used during program development but not part of final version

## Iteration

**reassignment:** Assigning a new value to a variable that already exists.

**update:** An assignment where the new value of the variable depends on the old.

**initialization:** An assignment that gives an initial value to a variable that will be updated.
increment: An update that increases the value of a variable (often by one).

**decrement:** An update that decreases the value of a variable.

**iteration:** Repeated execution of a set of statements using either a recursive function call
or a loop.

**infinite loop:** A loop in which the terminating condition is never satisfied.

**algorithm:** A general process for solving a category of problems

**while**
```python=
def countdown(n):
    while n > 0:
        print(n)
        n-=1
```
**break** - halts a loop
**Square roots** (Newton's Method)
![](https://i.imgur.com/AdoTQTj.png)
