# Inline-Loops for Efficient Array or String Operations

### Left-hand indexes \$, \$R, \$C and right hand inline-loop index \$1 can additionally control file sections, binomials, matrix products, concatenations, etc.

• Inline loops repeatedly apply an operator to integer ranges, Arrays, string expressions, or file-matrix expressions for efficient code and good readability.
• \$1 is the current loop index
• trace = +(matrix( \$1, \$1)
• \$, and \$R, and \$C are possible in the loop expressions
• Initial value = 1 for all \$SystemVariables
FromTo operations ":" operation( left_integer : right_integer )
+ (3 : 5) 3 + 4 + 5 = 12
= * (5 : 1) 5 * 4 * 3 * 2 * 1 = 5! = 120
sum = +(2^(0:-10)) 1+1/2+1/4+ .. 1/1024 == 1.9990234375
p = +( LOG(100:1)) 363.739375555564 == log(100) + log(99) + ... log(1)
q = LOG(*(100:1)) 363.739375555563 == log( 100 * 99 * ... 1 )
x = +(1.6 : 2.4) x is 2 == NINT(1.6) == NINT(2.4)
M = +( 1 : \$ )
 1 3 6 10 15 21 28 36 45
= *(n:1) / (*(k:1)) / (*(n-k:1)) n! / ( k! * (n-k)! ), same as:
binomial_coeff = *(n:n-k+1) / (*(k:1))
x = *(49:1) / (*(6:1)) / (*(49-6:1)) 6 from 49 = 13983816
y = *(49:49-6+1) / (*(6:1)) 49 choose 6 = 13983816
Arrays REAL X(3), Y(3), M(3,3), X8(8) ! samples
Y = (1,2,3) ^ (4,5,6) 1 32 729 temporary vector
d = /(Y) = Y(1) / Y(2) / Y(3)
Y = Y(3:1) reverse a vector
M = 1 / \$ M is (1, 1/2, 1/3, ..., 1/9)
 1 0.5 0.333333 0.25 0.2 0.166667 0.142857 0.125 0.111111
M = M( 3:1, 3:1) reverse row and column order
M = 1 / ( \$R + \$C - 1) !
 1 0.5 0.3333 0.5 0.3333 0.25 0.3333 0.25 0.2
= +( M( \$1, \$1) ) sum of matrix M diagonal elements
k = +( M >= 1/2 ) count matrix elements >= 0.5
l = +( M( 2 , : ) > 1/2 ) count row(2) elements > 0.5
n = +( M( : , 2 ) ) sum along column 2
o = +( M( : , 2:3) ) sum along columns 2 and 3
Z = +(M( \$C, \$1) * Y( \$1))
max = MAX( 4, -3.1, 4+4.1 ) 8.1
max_location = MAXLOC( 4, -3.1, 4+4.1 ) 3
X8 = *( 8 : 8- \$+1 ) / ( *( \$:1) ) 8 28 56 70 56 28 8 1
8th row of Pascals triangle

1st coeff ( 0! == 1) would provoke error
+( X8 ) + 1 256 == 2 ^ 8 sum of 8th row
 string_inline_loop CHARACTER S10*10 ! sample string S10 = CHAR( \$ + 64) ABCDEFGHIJ ( "A" has the Ascii number 65) S10 = &( CHAR(64+ \$1) & "," ) A, B, C, D ("&" is the Join operator) S10 = CHAR(64+ RAN(26)+0* \$ ) SQYWTYQHFG ( 0* \$ forces the inline loop to execute LEN(S10) = 10 times)
 file_section_inline_loop CHARACTER filename= 'TEST.TXT' For files \$1 is the row number op( filename( from : to ) see MatrixExplorer OPEN(FIle=filename, F=";/;/N;/") 3 columns separated by semicolons. 3rd column is Numerical string = && (filename( \$1, 2)) string gets all elements in column 2 separated by 1 space string = & (filename( \$1,2)&\$CRLF) elements in column 2 separated by carriagereturn & linefeed column-sum = + (filename( \$1,3)) all elements in column 3 added

Support HicEst   ⇾ Impressum