Skip to content

Commit

Permalink
cosmetic fixes, markdown linter
Browse files Browse the repository at this point in the history
  • Loading branch information
amanjeev committed Oct 23, 2023
1 parent babe939 commit 53431fc
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions training-slides/src/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

## Control Flow primitives

- `if` expressions
- `loop` and `while` loops
- `match` expressions
- `for` loops
- `break` and `continue`
- `return` and `?`
- `if` expressions
- `loop` and `while` loops
- `match` expressions
- `for` loops
- `break` and `continue`
- `return` and `?`

## Using `if` as a statement

- Tests if a boolean expression is `true`
- Parentheses around the conditional are not necessary
- Blocks need brackets, no shorthand
- Tests if a boolean expression is `true`
- Parentheses around the conditional are not necessary
- Blocks need brackets, no shorthand

```rust []
fn main() {
Expand All @@ -29,8 +29,8 @@ fn main() {

## Using `if` as an expression

- Every block is an expression
- Note the final `;` to terminate the `let` statement.
- Every block is an expression
- Note the final `;` to terminate the `let` statement.

```rust []
fn main() {
Expand Down Expand Up @@ -92,8 +92,8 @@ fn main() {

## `while`

- `while` is used for conditional loops.
- Loops while the boolean expression is `true`
- `while` is used for conditional loops.
- Loops while the boolean expression is `true`

```rust []
fn main() {
Expand All @@ -107,10 +107,10 @@ fn main() {

## Control Flow with `match`

- The `match` keyword does *pattern matching*
- You can use it a bit like an `if/else if/else` expression
- The first arm to match, wins
- `_` means *match anything*
- The `match` keyword does *pattern matching*
- You can use it a bit like an `if/else if/else` expression
- The first arm to match, wins
- `_` means *match anything*

```rust []
fn main() {
Expand All @@ -124,8 +124,8 @@ fn main() {

## `for` loops

- `for` is used for iteration
- Here `0..10` creates a `Range`, which you can iterate
- `for` is used for iteration
- Here `0..10` creates a `Range`, which you can iterate

```rust []
fn main() {
Expand All @@ -149,8 +149,8 @@ fn main() {

## `for` under the hood

- What Rust actually does is more like...
- (More on this in the section on *Iterators*)
- What Rust actually does is more like...
- (More on this in the section on *Iterators*)

```rust []
fn main() {
Expand Down Expand Up @@ -200,8 +200,8 @@ fn main() {

## `return`

- `return` can be used for early returns
- The result of the last expression of a function is always returned
- `return` can be used for early returns
- The result of the last expression of a function is always returned

```rust []
fn get_number(x: bool) -> i32 {
Expand Down

0 comments on commit 53431fc

Please sign in to comment.