mercredi 18 août 2021

Which one works faster?

Do these 2 have any differences?

if (condition)
{
    std::cout << "Condition is true";
}
else
{
    std::cout << "Condition is false";
}

OR

if (condition)
{
    std::cout << "Condition is true";
    return 0;
}
std::cout << "Condition is false";

I know that is not good to use the second one because maybe you have some more code after it. But at the end of the code that we don't have anything after that else, isn't it better to use the second one?

Aucun commentaire:

Enregistrer un commentaire