PREVIOUS(3) - [ENUMERATION] Previous enumeration value
result = previous (a [, stat])
elemental enumerator function previous(a,stat) result(answer)enumerator,intent(in) :: a integer(kind=**),intent(out),optional :: stat enumerator :: answer
o A shall be of enumeration type. o STAT is an integer with a decimal exponent range of at least four. o The returned value will be of the same type and kind as the argument. If A is equal to the first enumerator of its type, it is assigned
Previous enumeration value
o A : the starting value to locate the previous value relative to o STAT : If A is equal to the last enumerator of its type, it is assigned a processor-dependent positive value; otherwise, it is assigned the value zero. If STAT would have been assigned a nonzero value but is not present, error termination is initiated.
If A is equal to the first enumerator of its type, the value of the result is that of A. Otherwise, the value of the result is the enumerator preceding the value of A.
Example. If the enumerators of an enumeration type are EN1, EN2, EN3, and EN4, PREVIOUS (EN3) is equal to EN2, and PREVIOUS (EN1, ISTAT) is equal to EN1 and a positive value is assigned to ISTAT.
Sample program:
program demo_previous implicit noneResults:! Fortran 2023 strongly-typed enumeration enum, bind(c) :: color enumerator :: red, green, blue end enum
type(color) :: current_color
! Initialize to the first item current_color = red print *, "Initial position: ", int(current_color)
! Advance using the new NEXT intrinsic current_color = next(current_color) print *, "Next position (green): ", int(current_color)
! Advance again current_color = next(current_color) print *, "Next position (blue): ", int(current_color)
! Move backward using the new PREVIOUS intrinsic current_color = previous(current_color) print *, "Previous position (green): ", int(current_color)
end program demo_previous
> >
Fortran 2023
Fortran intrinsic descriptions
o Next enumeration value: NEXT(3) o Conversion of position to INTEGER: INT(3)
