19 lines
316 B
Markdown
19 lines
316 B
Markdown
## 3.1. The alternative
|
|
|
|
### The if structure
|
|
```Ocaml
|
|
if cond then expr1 else expr2
|
|
```
|
|
> ⚠️ `expr1` and `expr2` have to be the same type. `cond` is a `bool`
|
|
|
|
**For exemple**
|
|
```Ocaml
|
|
# if 1<2 then "higher" else "lower" ;;
|
|
-: string = "higher"
|
|
|
|
# let abs(x) =
|
|
if x>0 then x
|
|
else then x=x+(-x)+(-x) ;;;
|
|
|
|
```
|