Are these codes different?
I find when I research programming every book has a different way of doing the basics.
So I was wondering if these two codes are different or if they compile down to the same thing and what would be the benefit of one over the other.
if(a > b && b >c)
{}
if(a > b)
{
if(b > c)
开发者_Go百科 {}
}
They have the same effect (the program will do exactly the same) and they'll likely cause the same machine code to be emitted.
The first one is shorter, the second one might be more convenient to step over in the debugger (debuggers step over code line by line).
I think the second example creates an extra branch.
if(a > b && b >c)
{}
if(a > b)
{
if(b > c)
{}
}
They are same ....
They're technically the same. However, the second style is clearer if you have a corresponding "else" statement. Most importantly, different groups have different code style conventions and you might want to follow to the specific one your team are using.
if(a > b && b >c)
{}
else if(a > b)
{}
if(a > b)
{
if(b > c)
{}
else
{}
}
精彩评论