Skip to main content
8-Gravel
April 12, 2023
Solved

While loop problem with indexes

  • April 12, 2023
  • 2 replies
  • 2109 views

Hi!

 

Please, help me before I lose my mind finally. I have this simple while loop which is working just fine most of the cases but not now. I understand that the problem is with indexes but I just cannot see the solution. Please find the example file attached.

 

So what I'm trying to do is to compare the arrays xf and hs. Please see also the attached picture. I would want to get points compared and sorted like in the picture. From smallest to largest. English is not my native so I thought the picture would be more than thousand words.

 

Feel free also to suggest more simple way to do this if you like. Bear in mind that the dimensions and number of "i" usually changes with different cases I have. But one thing doesn't change and it's the number of equally divided spaces = 8.

 

Thanks a lot for your advice in advance!

 

-Harri

Best answer by Werner_E

Its sure bad habit to use the same name for the sum index and its end value, as ttokoro already remarked.

 

I have not looked at your program in detail but provide a solution depending of how I understood what you actually are after.
I prefer using small utility functions which do just one task and combine them to get what is needed.

See if the following (Prime 9 file attached) helps

Werner_E_0-1681305109693.png

 

2 replies

ttokoro
21-Topaz I
21-Topaz I
April 12, 2023

At first you should use the number >= i in your program.  

image.png     image.png

t.t.
ttokoro
21-Topaz I
21-Topaz I
April 13, 2023

image.png

t.t.
Werner_E25-Diamond IAnswer
25-Diamond I
April 12, 2023

Its sure bad habit to use the same name for the sum index and its end value, as ttokoro already remarked.

 

I have not looked at your program in detail but provide a solution depending of how I understood what you actually are after.
I prefer using small utility functions which do just one task and combine them to get what is needed.

See if the following (Prime 9 file attached) helps

Werner_E_0-1681305109693.png

 

23-Emerald IV
April 12, 2023

Werner's file converted to Prime 8.

 

Success!
Luc