if
- Purpose
- This sets up a test condition which can be used to control the subsequent action of the computer.
- Examples
if (month==12) println 'December' if (a==1) println 'One' else println 'Not one' if (answer=='Banana') fruit() if (height < 1.94 || age < 18) notAllowedOnThisRide() if (length != 5) tooShort() if (rate == 5) {y=6;z=8} else println 'Wrong rate' if (month == 11) {if (day == 5) println 'Guy Fawkes'} if (month == 1 && day == 1) println 'New Year' if (x) y=0 // x is zero or null- Description
- A statement forming part of the
if...elsestructure. The wordelseis optional. - Syntax
-
if (conditionalExpression) statement if (conditionalExpression) {statements} - Associated keywords
else