vendredi 24 septembre 2021

c++ Repeated if condition difference with bracket

I'm studying coding test with web compiler and i have an incomprehensible problem.

Does this bracket makes difference?

    if(i < waitLine)
    {
        if(bridge.update(truck_weights[i]))
            i++;
    }
    else
        bridge.update(0);

this one is ok.

    if(i < waitLine)
        if(bridge.update(truck_weights[i]))
            i++;
    else
        bridge.update(0);

but when i try this, compiler returns over time error. what's difference of this two style? isn't that else phrase just follow with first if condition?

Aucun commentaire:

Enregistrer un commentaire