POV-Ray : Newsgroups : povray.advanced-users : Negative subscript in while loop : Re: Negative subscript in while loop Server Time
4 Feb 2023 22:49:48 EST (-0500)
  Re: Negative subscript in while loop  
From: Tor Olav Kristensen
Date: 15 Jan 2023 21:35:00
Message: <web.63c4b7a931017364383c879289db30a9@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
>...

> // Insertion sort
> #for (I, 1, NoOfPoints)
>     #local Key = Bins[I];
>     #local TempF_0 = Points[I][0];
>     #local TempF_1 = Points[I][1];
>     #local J = I - 1;
>     #local Continue = (Bins[J] > Key);
>     #while (Continue)
>         #local Bins[J+1] = Bins[J];
>         #local Points[J+1][0] = Points[J][0];
>         #local Points[J+1][1] = Points[J][1];
>         #local J = J - 1;
>         #local Continue = (J >= 0);
>         #if (Continue)
>             #local Continue = (Bins[J] > Key);
>         #end // if
>     #end // while
>     #local Bins[J+1] = Key;
>     #local Points[J+1][0] = TempF_0;
>     #local Points[J+1][1] = TempF_1;
> #end // for
>...

If the assignments after the while loop goes wrong, then you can try
to change lines at the end of the while loop like this:

        #local Continue = (J >= 1);
        #if (Continue)
            #local J = J - 1;
            #local Continue = (Bins[J] > Key);
        #end // if

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

Copyright 2003-2021 Persistence of Vision Raytracer Pty. Ltd.