- 1
For_each_loop
I am just curious, appart from outputting elements directly from an array, is there any other special use for for each_loop. I'm not sure if we can actually do something like finding min and max within an array using for each loop. If that's possible, I'd love to know . Not just that but any other ways of using for each loop.
2 Answers
+ 6
I think you are asking about how to find min and max using foreach loop.
HINT: create a max and min variable and set a default value 0 to both of then then use foreach and check that if element is greater than max then, change the value of max to that element. Now it's your turn apply same type of logic with min also đ
+ 2
Thanks, I always go with for_loop but now I will try using it.