Conditionals
Groovy has the same conditionals that are used in Java. There are if, else if, and else conditionals in Groovy. The syntax used in Java for if, else if, and else statements is the same as it is in java. The only difference below is that Groovy does not use semi colons.
Groovy has the same conditionals that are used in Java. There are if, else if, and else conditionals in Groovy. The syntax used in Java for if, else if, and else statements is the same as it is in java. The only difference below is that Groovy does not use semi colons.
Groovy also allows assert statements to be used with the if, else if, and else statements. After a conditional statement is executed, variables can be set to other variables with the assert. This can be seen below. When users create a variable, the word def replaces the type of the variable.
Besides if, else if, and else statements, another type of conditional statement used in groovy are switch and cases. The value that the coder wishes to compare to all the other values goes inside the parameters for the switch. The value passed in the parameter is compared to all the cases. The syntax for this is underneath the switch line, there are brackets that signify that the cases go in between. After the word case, the value the coder wants to compare to the switch parameter goes there. This is then followed by a colon. At the end of the conditional, an assert statement can also be used. There are no semi colons involved in this. Below is a simple example of how switch and cases work as a conditional statement. Some coders prefer this manner of conditionals over if, else if, and else statements.



Comments
Post a Comment