Hey! Glad it piqued your curiosity.
To answer your questions :
- Yes, coroutines have read/write access to global variables. Since they run "on the main thread" (there's no multithreading), the usual warnings of race conditions and atomic read/writes or what have you do not apply, it's all safe.
- You can do conditionals and any kind of inner loop you want inside of the coroutine as well.
However, the sketch as you wrote it would not work, because you use delay().
Coroutines will only run in as a result of calling .update() on the Coroutines<N> object, so if you use delay() in your loop method, they won't get called in the idle time, unfortunately. One could override delay() to make it do that, but it makes it hard to read and understand. What I'd suggest instead is to move your loop() body to another coroutine, which would be able to interrupt itself with COROUTINE_YIELD at various points in time.
Same goes for delay() calls inside a coroutine. You should use coroutine.wait() followed by a COROUTINE_YIELD which effectively does the same thing, but makes sure the rest of the program can execute while your coroutine waits.
I'm not sure I understand the function of the delays in your loop function, so I don't know how to suggest a functioning way of doing what you want to do. In pseudocode or comments, can you describe the flow of what you're trying to achieve?