Using functional-style loops is *much less error-prone* to indexing
errors.
- Transform an array:
```julia
map(sqrt,[1,2,3,4,5])
map((x,y)->(x^2-exp(y)),[1,2,3],[-1,0,1])
```
- Summarize an array:
```julia
reduce(+,[1,2,3,4,5])
reduce((a,b)->"$b $a",["Use","the Force","Luke"])
reduce(*,[123;456],dims=1)
```
**Tricky question (<i class="twa twa-light-bulb"></i><i class="twa twa-light-bulb"></i><i class="twa twa-light-bulb"></i>):** What is the overhead of the "nice" loops?
# Making new arrays with loops
```julia
julia>[i*10+jfori=1:3,j=1:5]
3×5Matrix{Int64}:
1112131415
2122232425
3132333435
julia>join(sort([cforwordin["the result is 123","what's happening?","stuff"]
forcinword
ifisletter(c)]))
"aaeeeffghhhiilnnpprssssttttuuw"
```
# Control flow: subroutines (functions)
- Multi-line function definition
```julia
function combine(a,b)
returna+b
end
```
- "Mathematical" neater definition
```julia
combine(a,b)=a+b
```
-<iclass="twa twa-light-bulb"></i> Definition with types specified (prevents errors, allows optimizations!)