Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with Book Example

Tags:

d

Is it just me, or is there a problem with page 68 of "The D Programming Language" ? On this page, the author discusses D's syntax of if-else statements and how they nest. He first presents this example:

if(a == b)
    if(b == c)
        writeln("all are equal!");
    else
        writeln("a is different from b. Or is that so?");

He then points out that the else will bind to the second if. He then says that, to get the else to bind to the first if, one should use braces like so:

if(a == b) {
    if(b == c)
        writeln("all are equal!");
    else
        writeln("a is different from b. Or is that so?");
}

Am I missing the point completely, or would you have to do this:

if(a == b) {
    if(b == c)
        writeln("all are equal!");
}
else
    writeln("a is different from b. Or is that so?");
like image 260
debio Avatar asked Sep 14 '10 20:09

debio


People also ask

What is a good problem for a story?

Top 10 Story IdeasA middle-aged woman discovers a ghost. A woman who is deeply in love is crushed when her fiancé breaks up with her. A talented young man's deepest fear is holding his life back. A poor young boy or girl comes into an unexpected fortune.

What is an example of problem solution?

Problem-Solution Examples Solution 1: Change the laws to make it more difficult for couples to divorce. Solution 2: Impose a mandatory waiting period on couples before they can get married.


1 Answers

It is indeed an error. The errata for TDPL can be found here: http://www.erdani.com/tdpl/errata/index.php?title=Main_Page

like image 135
Jonathan M Davis Avatar answered Oct 04 '22 18:10

Jonathan M Davis