Lecture 2: control flow
- using Linux to do hw
- control flow (imperative programming)
- booleans and operators
- loops
booleans
- type bool
- implicit conversion (nonzero is true!)
- relational/comparison operators (watch out for = and ==)
- boolean operators (and,or,not)
if
- what code do I run? vs. what value do I return
- syntax -- what out for curly braces!
- example
- if/else and switch
if and :?
- ternary operator returns a value
- can have effects
- control flow rather than picking a value
loops
- iteration in Scheme: factorial
- iteration as updating an environment
- while loops in C
- tail recursion
- factorial in C
- prime number test
other kinds of loops
- for (repeat a code -- handles update for you)
- do while
- what loop do I use?