Peer reviewed: TrueFunder: Max-Planck-Gesellschaft; FundRef: http://dx.doi.org/10.13039/501100004189Funder: Alexander von Humboldt-Stiftung; FundRef: http://dx.doi.org/10.13039/100005156All animals face the challenge of finding nutritious resources in a changing environment. To maximize lifetime fitness, the exploratory behavior has to be flexible, but which behavioral elements adapt and what triggers those changes remain elusive. Using experiments and modeling, we characterized extensively how Drosophila larvae foraging adapts to different food quality and distribution and how the foraging genetic background influences this adaptation. Our work shows that different food properties modulated specific motor programs. Food quality controls the traveled distance by modulating crawling speed and frequency of pauses and turns. Food distribution, and in particular the food-no food interface, controls turning behavior, stimulating turns toward the food when reaching the patch border and increasing the proportion of time spent within patches of food. Finally, the polymorphism in the foraging gene (rover-sitter) of the larvae adjusts the magnitude of the behavioral response to different food conditions. This study defines several levels of control of foraging and provides the basis for the systematic identification of the neuronal circuits and mechanisms controlling each behavioral response