Brainardo gave an excellent answer. Here I supply some details.
Moses in Deuteronomy 9:
8 At Horeb you aroused the Lord’s wrath so that he was angry enough to destroy you. 9When I went up on the mountain to receive the tablets of stone, the tablets of the covenant that the Lord had made with you, I stayed on the mountain forty days and forty nights; I ate no bread and drank no water.
Elijah fasted similarly in 1 Kings 19:
8 So he got up and ate and drank. Strengthened by that food, he traveled forty days and forty nights until he reached Horeb, the mountain of God.
Ellicott explains:
Forty days and forty nights.--Unless this time includes, as has been supposed by some, the whole journey to and from Horeb, and the sojourn there, it is far in excess of what would be recorded for a journey of some two hundred miles. It may, therefore, be thought to imply an interval of retirement for rest and solitary meditation, like the sojourn of Moses in Horeb, and the sojourn of our Lord in the wilderness (Exodus 24:18; Matthew 4:2) during which the spirit of the prophet might be calmed from the alternations of triumph and despondency, to receive the spiritual lesson which awaited him. During all that time he went "in the strength" of the Divine food, that he might know that "man doth not live by bread alone, but by every word that proceedeth out of the mouth of God" (Deuteronomy 8:3).