How to call the Ax states in a loop?

You're writing to a pin, then reading from that pin a little while later.
What does this achieve?

Please use code tags.