I'm using the Salesforce APEX language, but I have a basic logic question using a loop structure. The loop syntax is similar to Java or C#.
I need to iterate over a series of values and check if the value I'm comparing is greater than the value I'm looping over and find the next highest value in the loop that the value is not greater than.
For example, let's say the value I need to check is 37 and the here is the list of values I'm looping over. Please note, the values can be in a random order and not sorted in ascending or descending order.
I want to stop on the iteration of 48 because 37 is greater than the 36 and less 48.
If the number was 100, I would want to stop on 144 because 100 is greater than 96 and less than 144.
How can I write a loop to check between values in a list?
Thanks for any help!