next up previous contents
Next: Array I/O Up: Arrays Previous: Array Sections - Visualisation

 

Array Sections

subscript-triplets specify sub-arrays. The general form is:

 
[< bound1 >]:[< bound2 >][:< stride >]

The section starts at < bound1 > and ends at or before < bound2 >. < stride > is the increment by which the locations are selected.

< bound1 >, < bound2 > and < stride > must all be scalar integer expressions. Thus

   A(:)        ! the whole array
   A(3:9)      ! A(m) to A(n) in steps of 1
   A(3:9:1)    ! as above
   A(m:n)      ! A(m) to A(n)  
   A(m:n:k)    ! A(m) to A(n) in steps of k
   A(8:3:-1)   ! A(8) to A(3) in steps of -1
   A(8:3)      ! A(8) to A(3) step 1 => Zero size
   A(m:)       ! from A(m) to default UPB
   A(:n)       ! from default LWB to A(n)
   A(::2)      ! from default LWB to UPB step 2
   A(m:m)      ! 1 element section
   A(m)        ! scalar element - not a section
are all valid sections.

For more information, click here gif

Now try this question gif


next up previous contents
Next: Array I/O Up: Arrays Previous: Array Sections - Visualisation

©University of Liverpool, 1997
Wed May 28 23:37:18 BST 1997
Not for commercial use.