Assalamualaikum ustaz. While I was praying, I became uncertain whether I farted or not. Can you explain what should I do in such a situation?
Alhamdulillah, praise and gratitude to Allah SWT for His countless blessings for us all. Praise and salutations to our beloved Prophet Muhammad PBUH, his family, companions and all those who follow his footsteps until the Last Day.
Doubt lexically means a subtle whisper from the wind and others. 
Allah SWT states:
وَلَقَدْ خَلَقْنَا الْإِنْسَانَ وَنَعْلَمُ مَا تُوَسْوِسُ بِهِ نَفْسُهُ
“And We have already created man and know what his soul whispers to him,” 
Syeikh al-Syanqiti said, “In this verse, Allah SWT explained that nothing is hidden from Him. What is hidden is apparent to Him and He is the All-Knowing of what is in the heart and what is apparent.” 
As for the term, the fuqaha’ divided the definition of doubt into several meanings:
- Doubt means a monologue such as a whisper in a person an everchanging feeling of whether he has or hasn’t done something.
- Doubt is something that is whispered by the shaytan to humans.
- Doubt is something whispered in a person that he became extra cautious that when he did something he will repeat it several times excessively.
- Doubt is a mind disease when he says something but his speech is useless. 
Regarding the above question, there is a hadith narrated by Abbad bin Tamim about a man who complained to Rasullullah PBUH that he is always distracted by something (which is hadas such as flatulence) in his prayers. The Prophet PBUH answered:
لاَ يَنْفَتِلْ – أَوْ لاَ يَنْصَرِفْ – حَتَّى يَسْمَعَ صَوْتًا أَوْ يَجِدَ رِيحًا
“He should not leave his prayers unless he hears sound or smells something.” 
An Islamic legal maxim states:
الْأَصْل بَقَاء مَا كَانَ عَلَى مَا كَانَ
“Basically, something remains according to its original state.”
For example, in explaining the above maxim, if a person wanted to fast and eat at the end of the night, then he becomes doubtful as to whether the sun has risen or not, then his fast is valid for the original ruling is the remaining night. 
I say the original ruling is he is in a pure state (ablution), then doubts came, is his ablution invalid? Then, leave the doubts and take what is originally certain. This is also in line with the maxim:
اليَقِينُ لَا يُزَالُ إِلَّا بِاليَقِين
“Certainty cannot be abrogated unless with another certainty.” 
Hence, if there is no smell or sound and more towards just doubts, then one can consider it is just the movement of the anal muscles. Sometimes air is trapped but it is on the outside. That is not fart. Or gas at the ends of the anus went up to the intestine, that a sensation is felt at the end. That is not farting too.
Thus, in this issue it is important that one is certain that one has farted or passed gas, hence invalidating ablution and prayer. If not, then the original ruling remains and the person is still in a pure state and he must continue his prayer.