// Copyright Contributors to the Open Shading Language project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage

shader
cyclic_read_in_loop_v4 (output color rgb = 0)
{
    int farthestIndex = -1;
    float dist = 0.0;
    for(int index = 0; index < 9; ++index)   {
        if (int(P[0]*256)%2 == 0) {
            for(int i2=0; i2 < 2; ++i2) 
            { 
                if(dist < P[0]) {
                    dist = (9 - index)*0.1;
                    farthestIndex = 9 - index;
                }
            }
        } else 
        {
            // Note that dist is not read by anything after the loop
            // Bug if the assignment to dist is not masked
            dist = 0;
            farthestIndex = 4;
        }        
    }
    
    rgb = float(farthestIndex)/9.0; 
}
