Skip to content

Files

Latest commit

 

History

History
25 lines (16 loc) · 476 Bytes

use_is_even_rather_than_modulo.md

File metadata and controls

25 lines (16 loc) · 476 Bytes

Pattern: Missing use of intValue.isOdd/isEven

Issue: -

Description

PREFER the use of intValue.isOdd/isEven to check for evenness.

Example of incorrect code:

bool isEven = 1 % 2 == 0;
bool isOdd = 13 % 2 == 1;

Example of correct code:

bool isEven = 1.isEven;
bool isOdd = 13.isOdd;

Further Reading