My friend told me a recent coding issue he had been asked during interviews., which i find it interesting so sharing it here.
Scenario 1:
for (i=0, i <N, i ++)
{
if (condition 1)
{ dostuff1 }
else
{ dostuff2 }
}
Scenario 2:
if (condition 1)
{ for (i=0, i <N, i ++)
{ dostuff1();
}
}
else
{
for (i=0, i <N, i ++)
{
dostuff2();
}
}
What are the pros and cons of using either one of these approaches? Please feel free to leave comments...It keep me thinking for a while but i got the answers....hehe...