Depends on the rule of that country. For example, you need a transit visa, free of charge, if you're flying via UAE. It takes 2-3 days to get this. However, some countries don't require. For example, Egypt or Oman don't require one if you stay in the airport for up to 48 hours.
I was about to...