jeudi 11 avril 2019

Does the Java compile differentiate these codes based on the indents?

I'm writing code for school in Eclipse. Whilst writing, I've come across the following question: I thougt, this code may not be compiled correctly, as this looks ambiguous to me. However, Eclipse does not give me an error message:

if (statement1)
    if(statement2)
        //code1
    else
        //code2

So I wondered how the compiler knows what the else-block refers to. Does it look at the indent? Or is it always the second if-statement?

Aucun commentaire:

Enregistrer un commentaire