|
It is common for students get the idea that a boolean expression can only occur in a test, such as in an if-statement. But that is not true. If x is 2, then expression x > 0 has value true. Instead of
if(x > 0)
{
return true;
}
else
{
return false;
}
why not just write
return x > 0;which has the same effect. Similarly, instead of
if(x > y)
{
v = false;
}
else
{
v = true;
}
why not just write
v = !(x > y);or, better yet,
v = x <= y;
|