Home > Software engineering >  Iterate through all the numerical and all
Iterate through all the numerical and all

Time:10-28

Such as a (I) is an array, how to traverse a (1) + a (2), a (1) + a (3),......, a (1) + a (100), a (1) + a (2) + a (3), a (1) + a (2) + a (4),......, a (1) + a (2) + a (100),......, a (1) + a (2) +...... + a (100), is to iterate through all the two values together, then iterate over all the three values of additive, to iterate through all the four values in...

CodePudding user response:

This I took only a stupid way,
 Sub demo () 
Dim arr, I As Long As Long j, k, As Long As l Long
Arr=Array (1, 2, 3, 4, 5, 6, 7, 8, 9)
For I=LBound (arr) To UBound (arr) - 1 'traverse two addition
For j=I + 1 To UBound (arr)
The Debug. Print arr (I) & amp; "+" & amp; Arr (j)
Next j
Next I
For I=LBound (arr) To UBound (arr) - 2 'traversal three addition
For j=I + 1 To UBound (arr) - 1
For k=j + 1 To UBound (arr)
The Debug. Print arr (I) & amp; "+" & amp; Arr (j) & amp; "+" & amp; Arr (k)
Next k
Next j
Next I
For I=LBound (arr) To UBound (arr) - 3 'traversal four addition
For j=I + 1 To UBound (arr) - 2
For k=j + 1 To UBound (arr) - 1
For l=k + 1 To UBound (arr)
The Debug. Print arr (I) & amp; "+" & amp; Arr (j) & amp; "+" & amp; Arr (k) & amp; "+" & amp; Arr (l)
Next l
Next k
Next j
Next I
End Sub

CodePudding user response:

Double loop can.
For I=1 to 99 do
K=I + 1
IBase=0
For j=1 to I
IBase=iBase + a (j)
Next
For j=k to 100
Print the iBase + a (j)
Next
Next
  •  Tags:  
  • VBA
  • Related