vendredi 28 août 2015

Double if else without brackets

I recently discovered that you can use the following syntax for if/else statements:

if (a)
    b = true;
else
    b = false;

when you nest another if clause inside this, it gets confusing

if (a)
    if (b)
         c = 3;
else
    c = 1;

but since the compiler ignores line indents, the compiler always parses this as (from what I understand)

if (a)
    if (b)
         c = 3;
    else
         c = 1;

Is it possible to achieve the second clause without using brackets? (I am aware that this makes no difference, but it is cleaner in my opinion)

Aucun commentaire:

Enregistrer un commentaire