Skip to content

Commit e0f9f89

Browse files
committed
tutorial: Remove confusing discussion about semicolons
This takes up a lot of words and isn't very clear. The previous discussion gets they idea across. /cc: #4217
1 parent 9cbc0fd commit e0f9f89

File tree

1 file changed

+0
-40
lines changed

1 file changed

+0
-40
lines changed

doc/tutorial.md

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -308,46 +308,6 @@ fn is_four(x: int) -> bool {
308308
}
309309
~~~~
310310

311-
If all those things are expressions, you might conclude that you have
312-
to add a terminating semicolon after *every* statement, even ones that
313-
are not traditionally terminated with a semicolon in C (like `while`).
314-
That is not the case, though. Expressions that end in a block only
315-
need a semicolon if that block contains a trailing expression. `while`
316-
loops do not allow trailing expressions, and `if` statements tend to
317-
only have a trailing expression when you want to use their value for
318-
something—in which case you'll have embedded it in a bigger statement.
319-
320-
~~~
321-
# fn foo() -> bool { true }
322-
# fn bar() -> bool { true }
323-
# fn baz() -> bool { true }
324-
// `let` is not an expression, so it is semicolon-terminated;
325-
let x = foo();
326-
327-
// When used in statement position, bracy expressions do not
328-
// usually need to be semicolon terminated
329-
if x {
330-
bar();
331-
} else {
332-
baz();
333-
} // No semi-colon
334-
335-
// Although, if `bar` and `baz` have non-nil return types, and
336-
// we try to use them as the tail expressions, rustc will
337-
// make us terminate the expression.
338-
if x {
339-
bar()
340-
} else {
341-
baz()
342-
}; // Semi-colon to ignore non-nil block type
343-
344-
// An `if` embedded in `let` again requires a semicolon to terminate
345-
// the `let` statement
346-
let y = if x { foo() } else { bar() };
347-
~~~
348-
349-
This may sound intricate, but it is super-useful and will grow on you.
350-
351311
## Types
352312

353313
The basic types include the usual boolean, integral, and floating-point types.

0 commit comments

Comments
 (0)