stylistic:tone, structural:reformatting, stylistic:style_transfer
Ecology

As ubiquitous insects, dipterans play an important role at various trophic levels both as consumers and as prey. In some groups the larvae complete their development without feeding, and in others the adults do not feed. The larvae can be herbivores, scavengers, decomposers, predators or parasites, with the consumption of decaying organic matter being one of the most prevalent feeding behaviours. The fruit or detritus is consumed along with the associated micro-organisms, a sieve-like filter in the pharynx being used to concentrate the particles, while flesh-eating larvae have mouth-hooks to help shred their food. The larvae of some groups feed on or in the living tissues of plants and fungi, and some of these are serious pests of agricultural crops. Some aquatic larvae consume the films of algae that form underwater on rocks and plants. Many of the parasitoid larvae grow inside and eventually kill other arthropods, while parasitic larvae may attack vertebrate hosts.

Whereas many dipteran larvae are aquatic or live in enclosed terrestrial locations, the majority of adults live above ground and are capable of flight. Predominantly they feed on nectar or plant or animal exudates, such as honeydew, for which their lapping mouthparts are adapted. Some flies have functional mandibles that may be used for biting. The flies that feed on vertebrate blood have sharp stylets that pierce the skin, with some species having anticoagulant saliva that is regurgitated before absorbing the blood that flows; in this process, certain diseases can be transmitted. The bot flies (Oestridae) have evolved to parasitize mammals. Many species complete their life cycle inside the bodies of their hosts. The larvae of a few fly groups (Agromyzidae, Anthomyiidae, Cecidomyiidae) are capable of inducing plant galls. Some dipteran larvae are leaf-miners. The larvae of many brachyceran families are predaceous. In many dipteran groups, swarming is a feature of adult life, with clouds of insects gathering in certain locations; these insects are mostly males, and the swarm may serve the purpose of making their location more visible to females.

Most adult diptera have their mouthparts modified to sponge up fluid. The adults of many species of flies (e.g. Anthomyia sp., Steganopsis melanogaster) that feed on liquid food will regurgitate fluid in a behaviour termed as "bubbling" which has been thought to help the insects evaporate water and concentrate food or possibly to cool by evaporation. Some adult diptera are known for kleptoparasitism such as members of the Sarcophagidae. The miltogramminae are known as "satellite flies" for their habit of following wasps and stealing their stung prey or laying their eggs into them. Phorids, milichids and the genus Bengalia are known to steal food carried by ants. Adults of Ephydra hians forage underwater, and have special hydrophobic hairs that trap a bubble of air that lets them breathe underwater.