Just as one who needs to relieve herself and cannot wait 72 minutes is forbidden to pray, so too she may not recite berakhot, say Shema, or study Torah, for it is not proper to engage in sacred matters when one’s body is offensive. Yet there is a significant difference between the Amida and other sacred matters (“devarim she-bikdusha”). During the Amida, we are like subjects standing before the King. If one does not pray in the proper manner, she disgraces the honor of heaven, and her prayer is an abomination. Therefore, when the person reciting the Amida cannot control her need for 72 minutes, her prayer is invalid. This is not so regarding other matters of sanctity. While saying them, one is not considered to be standing before the King. Hence, be-di’avad, if she recites berakhot or Shema even when she is not able to control her need for 72 minutes, she fulfills her obligation (MB 92:6; BHL s.v. “Afilu Be-divrei Torah”; Kaf Ha-ĥayim 3).
One who can wait 72 minutes, according to most Aĥaronim, is permitted le-khatĥila to recite berakhot and study Torah, though there are those who say that it is preferable for her to relieve herself first (MB 92:7). However, if she must exert herself in doing so, she is not required to relieve herself.
One who begins studying Torah when she does not need to relieve herself, but in the course of studying feels a need, to the point where she can no longer wait 72 minutes, should le-khatĥila go and relieve herself. If she is in the middle of a topic, some say that she may continue to learn until she completes it (BHL 92:2 s.v. “Koreh”; Yalkut Yosef, vol. 2, p. 338), whereas others say that she should relieve herself immediately (Kaf Ha-ĥayim 3:48).
If she is teaching Torah, she should finish her class and then relieve herself, for human dignity (kevod ha-briyot) is so great that it overrides the rabbinic prohibition of “bal teshaktzu” (MB 92:7). Likewise, it is proper that a student in a class waits and does not leave in the middle out of respect for the class, as long as the need to relieve herself is not that great. If, out of respect for the class, we are lenient regarding the prohibition of “bal teshaktzu,” we certainly refrain as much as possible from going in and out of the class for other reasons, and it is certainly forbidden to disrupt the class by talking.