Your workflow works, though since you have your messageboxes within the loop they popup each time.
Since the max value 9 is at the end of the array, it is determened only at the end of your loop, and untill then it pops up 7 as max 4 times.
If you move the 2 messageboxes outside your loop you won’t get those in-between messages anymore, and only the final result with 9 as max, and 2 as min.