Flowchart how to do in loop part from the code?

Your loop function is linear - not really a flow chart, it's just top to bottom straight line.

I don't really see a good reason why the text array has global scope.