@@ -204,16 +204,13 @@ paretheses, while their bodies *must* be wrapped in
204
204
brackets. Single-statement, bracket-less bodies are not allowed.
205
205
206
206
~~~~
207
- # fn calibrate_universe() -> bool { false }
208
- # fn party_on() {}
209
- # fn panic() {}
207
+ # fn recalibrate_universe() -> bool { true }
210
208
fn main() {
211
- while calibrate_universe() {
212
- /* Ensure that basic math still operates is expected */
213
- if 2*20 > 30 {
214
- party_on(); // That's a relief
215
- } else {
216
- panic();
209
+ /* A simple loop */
210
+ loop {
211
+ // A tricky calculation
212
+ if recalibrate_universe() {
213
+ return;
217
214
}
218
215
}
219
216
}
@@ -438,10 +435,9 @@ The nil literal is written just like the type: `()`. The keywords
438
435
439
436
Character literals are written between single quotes, as in ` 'x' ` . Just as in
440
437
C, Rust understands a number of character escapes, using the backslash
441
- character, ` \n ` , ` \r ` , and ` \t ` being the most common.
442
-
443
- String literals allow the same escape sequences. They are written
444
- between double quotes (` "hello" ` ). Rust strings may contain newlines.
438
+ character, ` \n ` , ` \r ` , and ` \t ` being the most common. String literals,
439
+ written between double quotes, allow the same escape sequences. Rust strings
440
+ may contain newlines.
445
441
446
442
## Operators
447
443
@@ -482,14 +478,19 @@ a syntax extension is being used, the names of all syntax extensions end with
482
478
which is ` fmt! ` , a ` sprintf ` -style text formatter that is expanded at compile
483
479
time.
484
480
485
- ~~~~
486
- io::println(fmt!("%s is %d", ~"the answer", 42));
487
- ~~~~
488
-
489
481
` fmt! ` supports most of the directives that [ printf] [ pf ] supports, but
490
482
will give you a compile-time error when the types of the directives
491
483
don't match the types of the arguments.
492
484
485
+ ~~~~
486
+ # let mystery_object = ();
487
+
488
+ io::println(fmt!("%s is %d", "the answer", 43));
489
+
490
+ // %? will conveniently print any type
491
+ io::println(fmt!("what is this thing: %?", mystery_object));
492
+ ~~~~
493
+
493
494
[ pf ] : http://en.cppreference.com/w/cpp/io/c/fprintf
494
495
495
496
You can define your own syntax extensions with the macro system, which is out
@@ -505,11 +506,11 @@ compulsory, an optional `else` clause can be appended, and multiple
505
506
506
507
~~~~
507
508
if false {
508
- io::println(~ "that's odd");
509
+ io::println("that's odd");
509
510
} else if true {
510
- io::println(~ "right");
511
+ io::println("right");
511
512
} else {
512
- io::println(~ "neither true nor false");
513
+ io::println("neither true nor false");
513
514
}
514
515
~~~~
515
516
0 commit comments