max function implementation by iteration