Euphoria has some very useful methods built into Euphoria’s standard library packages. They enable us to get simple tasks done in our codes without writing them again.
For example, to check if a particular number is divisible by 2 or not, we can use the is_even()
method.
is_even()
method?To check if a number is divisible by 2 is the same as checking if such a number is an even number. So what the is_even()
method does is to check when the integer provided as the argument is divided by 2, will it have a remainder. If it has, then it is not an even number, but if it does not, then it is an even number.
We can even develop our own function to do this hassle-free. But to save developers time and increase productivity, Euphoria has bundled the is_even()
method and another helper method as part of the standard library package methods. All we need to do is include the package. We are ready.
is_even(integer_to_check)
integer_to_check
: This integer will be checked to see if it is even or not.The is_even()
method returns:
1
: if the value provided is an even number.
0
: if the value provided is not an even number.
In the code below, we’ll check if numbers from 10
to 20
are even or not.
Note: To use this method, we must include the
math.e
file from standard librarystd
like soinclude std/math.e
include std/math.e for i = 10 to 20 do ? {i, is_even(i)} end for
Here is a line-by-line explanation of the above code:
math.e
file from the standard library files.for
loop starts and ends at line 5. Each iteration of the loop invokes the is_even()
method.?
symbol prints the code output on the screen. The is_even()
method checks if the numbers provided are even or not.RELATED TAGS
CONTRIBUTOR
View all Courses