Just as one who needs to relieve himself and cannot wait 72 minutes is prohibited from reciting the Amidah, so too, he is prohibited from reciting berachot, saying Shema, and learning Torah, for it is not proper to engage in matters of sanctity when one’s body is offensive. However, there is a significant difference between the Amidah and other matters of sanctity. In the Amidah we resemble people standing in front of the King. If one does not pray in the proper manner, he disgraces the respect of Heaven and his prayer is an abomination. Therefore, when the person reciting the Amidah cannot control his need for 72 minutes, his 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, b’dieved, if he recites berachot or Shema even when he is not able to control his need for 72 minutes, he fulfills his obligation (Mishnah Berurah 92:6; Bei’ur Halachah s.v. “Afilu B’Divrei Torah”; Kaf HaChaim 3).
One who can wait 72 minutes, according to most Acharonim, is permitted l’chatchilah to recite berachot and learn Torah, though there are those who say that it is preferable for him to relieve himself first (Mishnah Berurah 92:7). However, if he must exert himself in doing so, he does not need to relieve himself.
A person who starts to learn when he does not need to relieve himself, but in the course of learning feels a need, to the point where he can no longer wait 72 minutes, should l’chatchilah go and relieve himself. If he is in the middle of a subject of study, some say that he may continue to learn until he finishes that subject (Bei’ur Halachah 92:2 s.v. “Koreh”; Yalkut Yosef, part 2, p. 338), whereas others say that he should go relieve himself immediately (Kaf HaChaim 3:48). If he is teaching Torah, he should finish his class and then relieve himself, for human dignity (kevod habriyot) is so great that it overrides the rabbinic prohibition of “Do not abominate oneself” (Mishnah Berurah 92:7).
. It is implied from Aruch HaShulchan 92:1, that even if the time to recite the Shema will pass, l’chatchilah he should not recite it. However, this matter requires further study since presumably it is better that he recite the Shema so that he will not miss saying it (for in this case there is no fear of reciting a berachah in vain).