Forum Discussion
nmrao
Champion Level 1
2 years agoHere is the simple example which uses list of items in the box and checks using "contains".
You can try with different value for favouriteToy which is not in toyBox and see the output.
Below uses Ternary operator. For more details check documentation here
Of course, one can use if / else too
In this example, just logging different things to demonstrate. One can write different statements instead as needed in each case i.e., true or false.
def favouriteToy = 'car'
def toyBox = ['car', 'bat', 'helicopter', 'bike', 'tractor', 'truck', 'train']
toyBox.contains(favouriteToy) ? log.info("Toy box has favourite toy") : log.info("Toy box does not have ${favouriteToy}")