This can be moved up a bit, somewhere before: while (level > 1 && experience < Player::getExpForLevel(level)) { and the result can be re-used here to make less calls to that function.