Often programmers use boolean functions that return boolean values true or false (trueor false)
Such functions are useful for check some property.
Consider two examples of writing a logical function that checks a number for evenness
1) Better way:
expression result
n % 2 == 0
will be true (True) or false (False)
No need to write a conditional statement! |
2) Don't do that!
You can write it like that, but it’s better not to do a longer record anyway |
static Boolean isEven(int n)
{
return (n % 2 == 0);
}
|
static Boolean isEven(int n)
{
if (n % 2 == 0)
return true;
else
return false;
}
|
And the last note about working with functions and procedures: the number of functions and procedures in the program is not limited. In addition, one subroutine can call another subroutine and even itself.