# Possible to use algebraic expression as array subscript?

**URL:** <https://fortran-lang.discourse.group/t/possible-to-use-algebraic-expression-as-array-subscript/291>\
**Category:** Uncategorized\
**Created:** [September 6, 2020, 5:02pm UTC](https://fortran-lang.discourse.group/t/possible-to-use-algebraic-expression-as-array-subscript/291 "2020-09-06T17:02:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lanast](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@lanast](https://fortran-lang.discourse.group/u/lanast)\
**Post date:** [September 6, 2020, 5:02pm UTC](https://fortran-lang.discourse.group/t/possible-to-use-algebraic-expression-as-array-subscript/291/1 "2020-09-06T17:02:00Z")

</div>

Dear Fortran community,  
is it possible to use an algebraic expression of integers as the subscripts of an array `A`, for accessing or for manipulating elements of an array?  
I would like to implement following code:  
` DO i = 1,N1`  
` DO j = 1,N2`  
` A((i+j),((i-1)*(j-1)+j)) = ...`  
` END DO`  
` END DO`

It appears that the compiler requires, that the resulting indices are not out of the range which was used to initalize the matrix.  
Thank you

---

<div class="post-metadata">

**Author:** ![billlong](https://avatars.discourse-cdn.com/v4/letter/b/71e660/32.png) [@billlong](https://fortran-lang.discourse.group/u/billlong)\
**Post date:** [September 6, 2020, 6:19pm UTC](https://fortran-lang.discourse.group/t/possible-to-use-algebraic-expression-as-array-subscript/291/2 "2020-09-06T18:19:35Z")

</div>

Yes. Integer valued expressions are fine as subscript values. Those values are required to be within the range [lower\_bound, upper\_bound] for each dimension. That is a standard requirement, which some compilers enforce.

---

<div class="post-metadata">

**Author:** ![lanast](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@lanast](https://fortran-lang.discourse.group/u/lanast)\
**Post date:** [September 7, 2020, 10:01am UTC](https://fortran-lang.discourse.group/t/possible-to-use-algebraic-expression-as-array-subscript/291/3 "2020-09-07T10:01:28Z")

</div>

Thank you @billlong, this clarifies it
