cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

While loop problem with indexes

HS_10137076
4-Participant

While loop problem with indexes

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

 

View solution in original post

5 REPLIES 5
ttokoro
20-Turquoise
(To:HS_10137076)

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

image.png     image.png

ttokoro
20-Turquoise
(To:ttokoro)

image.png

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

 

LucMeekes
23-Emerald III
(To:Werner_E)

Werner's file converted to Prime 8.

 

Success!
Luc

HS_10137076
4-Participant
(To:Werner_E)

Thank you Werner! I would say your solution is "little" more simple and therefore better than mine 😀. I get that it's easier to check and control the calculations if the functions are done like you have.

 

Please find also the file in where I managed to fix the problem also. I added some restrictions more to indexes and now it seems to work at least with those variables. But I will change my functions to match your examples.

Top Tags