Modulo
Take a look at line 26
. The %
operator is called modulo. Modulo computes a remainder. The modulo operator provides a way to execute code once in every several iterations of a loop. We are using modulo here to check whether a number variable can be perfectly divided by 2. If the number can be divided, the remainder will be equal to 0, so we will have an even number! Otherwise, the number must be odd.
Coming back to line 14
, a method is a substitute for a value and IsEvenMethod
is a return
type method, returning Boolean value inside if
statement. In simpler words, when the value of i
is passed to IsEvenNumber
, the method returns a true or false value. If the value is true, line 15
will be executed and the message will be printed on the Console
window.
Let's test the code. If all goes well, you should see lots of messages printed on the Console
window, as follows:
All went very well then! Go ahead and try to experiment with this code. Why not run the loop 1,000 times? Do it! Computers can...