There are occasions in which in an array, you will need to find either the minimum value(s) or the maximum value(s).
To accomplish this you have to have two variables, one to store the element value in the array, and another to consider the actual value in that element (Max would be the variable that stores the currently biggest number and MaxIndex stores where the biggest number index is located at).
Once all the elements have been run through, Max / Min will contain the largest / smallest value and maximumIndex / minimumIndex will contain the index of the largest / smallest value.
BEGIN MaxValue
Get List_Array
Length = Length of list // the number of values in the array
Max = 0 //sets the largest value at 0 - this assumes the values in the array are all numbers greater than 0
position = 0
FOR count = 0 to length - 1 // assume a zero index start.
IF List_Array ( count ) > Max // if the value being checked is greater than the current Max, then...
THEN Max = List_Array (count), position = count // ... make the current value the new Max
ELSE ( do nothing)
NEXT count
Display "The maximum value is " + Max + " The position of the Max is " + position
END MaxValue
BEGIN
Get List_Array
Length = Length of list
Min = 999 // this assumes the minimum value is less than 999.
position = 0
FOR count = 0 to length - 1 // assume a zero index start
IF List_Array ( count ) < Min // reverse the relational operator
THEN Min = List_Array (count), position = count // this records both the lower value and its position in the array
ELSE ( do nothing)
NEXT count // for every FOR, there must be a NEXT....
Display "The minimum value " + Min + " The position of the Min is " + position
END
These samples are well commented as well.