listings-Chap08-README.md
Listings of Chap08.docx
This is linked summary of the listings. You can also view it on one page.
- Listing 08.1: Calculates all prime numbers in a user-defined range.
- Book: lst-0001-book.cpp
- Godbolt: lst-0001-godb.cpp, https://godbolt.org/z/Y33Tzcf5T
- Listing 08.2: This “for” refers to only one statement.
- Book: lst-0002-book.cpp
- Listing 08.3: A statement block is enclosed in { and }.
- Book: lst-0003-book.cpp
- Listing 08.4: Where statements are allowed, you can also create a block.
- Book: lst-0004-book.cpp
- Listing 08.5: Using “result” twice as a new variable in one block is not allowed.
- Book: lst-0005-book.cpp
- Listing 08.6: Too many variables are also not good.
- Book: lst-0006-book.cpp
- Listing 08.7: Empty statements everywhere.
- Book: lst-0007-book.cpp
- Listing 08.8: With auto, you can also initialize multiple variables at once.
- Book: lst-0014-book.cpp
- Godbolt: lst-0014-godb.cpp, https://godbolt.org/z/xWbqeeq3n
- GodboltId:3zo8GnbW3
- Book: lst-0015-book.cpp
- Godbolt: lst-0015-godb.cpp, https://godbolt.org/z/3zo8GnbW3
- Listing 08.9: These are all expressions used as statements.
- Book: lst-0016-book.cpp
- Listing 08.10: These if statements contain initializers.
- Book: lst-0023-book.cpp
- Godbolt: lst-0023-godb.cpp, https://godbolt.org/z/d6PscKx4M
- Listing 08.11: The compiler can evaluate the condition at compile time.
- Book: lst-0024-book.cpp
- Godbolt: lst-0024-godb.cpp, https://godbolt.org/z/Ycse4EWav
- Listing 08.12: The loop runs 100 times.
- Book: lst-0025-book.cpp
- Godbolt: lst-0025-godb.cpp, https://godbolt.org/z/h466fYq4W
- Listing 08.13: The body of a “do-while” loop is executed at least once.
- Book: lst-0027-book.cpp
- Godbolt: lst-0027-godb.cpp, https://godbolt.org/z/6hh5KhExM
- Listing 08.14: Sum with a “for” loop.
- Book: lst-0028-book.cpp
- Godbolt: lst-0028-godb.cpp, https://godbolt.org/z/7foYcMMaz
- Listing 08.15: “for” loop with empty initialization part.
- Book: lst-0029-book.cpp
- Godbolt: lst-0029-godb.cpp, https://godbolt.org/z/185ha3q3f
- Listing 08.16: Loops without conditions must be terminated in some other way.
- Book: lst-0030-book.cpp
- Listing 08.17: You can recognize the range-based “for” loop by the colon.
- Book: lst-0031-book.cpp
- Listing 08.18: Each “case” covers one scenario, and nowhere was the “break” forgotten.
- Book: lst-0032-book.cpp
- Godbolt: lst-0032-godb.cpp, https://godbolt.org/z/Y4W11oW8b
- Listing 08.19: Very rarely are there “case” blocks without “break”—and even more rarely meaningful ones.
- Book: lst-0033-book.cpp
- Godbolt: lst-0033-godb.cpp, https://godbolt.org/z/jaMTcshEf
- Listing 08.20: With break, you terminate a loop prematurely.
- Book: lst-0034-book.cpp
- Godbolt: lst-0034-godb.cpp, https://godbolt.org/z/75h9Y95vf
- Listing 08.21: With “return”, the current function is exited. If necessary, provide a value for the return.
- Book: lst-0035-book.cpp
- Godbolt: lst-0035-godb.cpp, https://godbolt.org/z/5ddxa9v1j
- Listing 08.22: Avoid goto statements.
- Book: lst-0036-book.cpp
- Godbolt: lst-0036-godb.cpp, https://godbolt.org/z/ohd5Pr8fb
- Listing 08.23: One less function, but one label and two more “goto” statements.
- Book: lst-0037-book.cpp
- Godbolt: lst-0037-godb.cpp, https://godbolt.org/z/fnsWhn5T3
- Listing 08.24: As a preview, here is your first exception handling with “try” and “catch”.
- Book: lst-0038-book.cpp
- Godbolt: lst-0038-godb.cpp, https://godbolt.org/z/jhPaEjh1r