Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate nested ifs (bis) #4

Merged
merged 2 commits into from
Jan 21, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions outline/flow_control.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,16 @@ ng-click="block21=!block21"></button>
{: ng-show="block62" .description}

```clojure
(cond
(if (> (+ y 40) 150) ; if over the top
-150 ; then start at the bottom
(if (< (+ y 40) -150) ; if below the bottom
150 ; then start at the top
(+ y 40))) ; otherwise move

```

```clojure
(cond ; so much more legible than nested ifs
(> (+ y 40) 150) -150
(< (+ y 40) -150) 150
:else (+ y 40)))
Expand All @@ -192,10 +201,24 @@ ng-click="block21=!block21"></button>
predicate1 expression-to-evaluate-when-predicate1-is-true
predicate2 expression-to-evaluate-when-predicate2-is-true
...
:else expression-to-evaluate-when-all-above-are-false)
:else expression-to-evaluate-when-all-above-are-false)
```
</section>

<section ng-controller="NarrativeController">
#### `cond` example

```clojure
(cond
(< x 10) "x is smaller than 10"
(< 10 x 20) "x is between 10 and 20"
(< 20 x 30) "x is between 20 and 30"
(< 30 x 40) "x is between 30 and 40"
:else "x is bigger than 40")
```

</section>

<section>
#### EXERCISE 2: Y value within a frame - part 2
{: .slide_title .slide}
Expand Down