Skip to main content
14-Alexandrite
December 17, 2025
Solved

How to write loop inside another loop

  • December 17, 2025
  • 2 replies
  • 502 views

Hi there, 

I have a variable with 100 values inside and I want to check every 5 values to find the minimum between them. I need to do that through the entire values ... this means 20 times . I tried to write it this way but not working : 

YA_10963798_0-1765960507471.png

 

YA_10963798_0-1765959984808.png

z , and q are related to each other . q is the resistance at z depth .. 

the results I expect is : the program will check q at each z and will choose the minimum (q , 15MPa) but will do this in intervals 5 values by 5 values . 

 

the sheet can't be attached again . I attached  zip file 

thanks 

Yusra

 

Best answer by Werner_E

Here are two implementations of how I understood your question.

The first uses the "submatrix" function to get the minimum of the five values, the second uses a nested for-loop.

Werner_E_0-1765984143091.png

Prime 11 sheet attached

 

2 replies

23-Emerald IV
December 17, 2025

Hi Yusra,

 

Try this:

LucMeekes_0-1765983381872.png

You should be able to call it with:

LucMeekes_1-1765983469479.png

But you'll also need an associated Z array:

LucMeekes_2-1765983536912.png

LucMeekes_3-1765983554729.png

Now you can plot Q versus Z.

 

Success!
Luc

14-Alexandrite
December 18, 2025

Hi Luc 

in Z array why you used (i-1)*5+3 

Thanks 

23-Emerald IV
December 18, 2025

I had to reduce the length of array z to that of Q to make array Z. I decided to take the  middle value of each group of 5 z values for that.

 

Success!

Luc

Werner_E25-Diamond IAnswer
25-Diamond I
December 17, 2025

Here are two implementations of how I understood your question.

The first uses the "submatrix" function to get the minimum of the five values, the second uses a nested for-loop.

Werner_E_0-1765984143091.png

Prime 11 sheet attached

 

14-Alexandrite
December 18, 2025

there is one remark here .. the result should be 100 values not 20 values only..... I wanted to compare one by one in each 5 values 

which means we divide the 100 values to 20 groups in each group 5 values > and then compare each member to 15 and choose the minimum... 

The end results will still be 20 groups but with the minimum values.  

 

25-Diamond I
December 18, 2025

Unfortunately, I cannot identify a comprehensible algorithm in your description. You may need to provide one or, better yet, several concrete examples to clarify the task.
Do you mean that the desired result should consist of groups of five with identical values?