sample encoder using if-else statement