This is confusing and I am not sure that it is correct. Instead, can you use the usual loop/function without "reached" to get an initial value for i and then, when you must, use a simpler loop to slightly adjust i.