Why doesn't the brain get into infinite loops when being queried? In computer programming, when algorithms are using loops/recursion without an exit condition, the algorithm will never end or get out of resources.

How does the brain work around getting into endless loops/recursions due to interconnected nets, i.e. when there are circularities in the nets? For example, neuron A activates neuron B which activates C which activates A, and so on. Or are there no circularities in the brain structure?
The brain often does create looping conditions. When these loops involve a large number of neurons, we call it a seizure. An analogy in electrical engineering would be a feedback loop -- such as literal feedback between a microphone and speakers. In the brain, fortunately, these loops are usually self-dissolving since the neurons involved will often run out of neurotransmitter or energy, or inhibitory neurons will get involved (like referees breaking up a fight). Many of the neurotransmitters and hormones in the body act as regulators of ongoing processes. There are almost always negative feedback mechanisms whose purpose is to prevent overload on various systems. The equivalent in programming would be using a counter variable in a while loop to break if it loops too many times.

This all, of course, was with respect to short pathways (small number of links). Larger, more complex pathways such as thoughts and goals are probably handled in part by different mechanisms, such as the instinct of not wanting to waste too much time getting nowhere. At the same time, getting frustrated and rage quitting is a perfect example of hormones and neurotransmitters rising to the point of stopping the loop of trying to do something that is not working as desired.