While Loop Text Not Displaying

I’m having a problem getting text to display in a while loop. In the example below, the text in the while loop doesn’t display. If the repeat loop is uncommented, the text does display. What am I not understanding about while. Thanks.

-- Loops

-- Use this function to perform your initial setup
function setup()
    Index2 = 1
    Index3 = 1
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)
    fill(191, 186, 49, 255)
    for Index = 1,10 do
        text ( "For: " .. Index, WIDTH * .25, HEIGHT/20 * Index )
    end
    while Index2 <= 10 do
        text ( "While: " .. Index2, WIDTH * .5, HEIGHT/20 * Index2 )
        Index2 = Index2 + 1
    end
--[[
    repeat
        text ( "Repeat: " .. Index3, WIDTH * .75, HEIGHT/20 * Index3 )
        Index3 = Index3 + 1
    until Index3 == 11
--]]
end

@DaveW You need to put the index2 and 3 initialization in the draw routine. With them in setup, they’re initialized once, then in draw they were beyond the limits you were checking for. They would have displayed what you wanted the first time draw was called, but because background clears the screen each time draw is called, you didn’t see the results you were expecting.

-- Loops

function setup()
end

function draw()
    background(40, 40, 50)
    Index2 = 1
    Index3 = 1
    fill(191, 186, 49, 255)
    for Index = 1,10 do
        text ( "For: " .. Index, WIDTH * .25, HEIGHT/20 * Index )
    end
    while Index2 <= 10 do
        text ( "While: " .. Index2, WIDTH * .5, HEIGHT/20 * Index2 )
        Index2 = Index2 + 1
    end
    repeat
        text ( "Repeat: " .. Index3, WIDTH * .75, HEIGHT/20 * Index3 )
        Index3 = Index3 + 1
    until Index3 == 11
end

@dave1707 Thanks, I was looking for my problem in the wrong place.