Forum Discussion
nmrao
2 years agoChampion Level 3
Here 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}")
Related Content
- 2 years ago
- 4 years ago
- 2 years ago
Recent Discussions
- 18 hours ago
- 17 days ago