Guard Clause
Uses
if (x < 1) { return "Not a natural number"; } else { return " a natural number"; }if (x < 1) { return "Not a natural number"; } return " a natural number";if (isNull(x)) { throw new IllegalArguementException(); }void describeEating(Item item) { if (!item.isFood) { print("Wait, that's not even food!"); } else { if (item.isDelicious) { print("Hmm, that was good."); } else { print("Not bad. Nutritious."); } } }void describeEating(Item item) { if (!item.isFood) { print("Wait, that's not even food!"); return; } if (item.isDelicious) { print("Hmm, that was good."); } else { print("Not bad. Nutritious."); } }
Benefits
Issues
Links
Last updated