Learning can allow individuals to increase their fitness in particular environments. The advantage to learning depends on the predictability of the environment and the extent to which animals can adjust their behaviour. Earlier general models have investigated when environmental predictability might favour the evolution of learning in foraging animals. Here, we construct a theoretical model that predicts the advantages to learning using a specific biological example: oviposition in the Lepidoptera. Our model includes environmental and behavioural complexities relevant to host selection in these insects and tests whether the predictions of the general models still hold. Our results demonstrate how the advantage of learning is maximised when within-generation variability is minimised (the local environment consists mainly of a single host plant species) and between-generation variability is maximised (different host plant species are the most common in different generations). We discuss how our results: (a) can be applied to recent empirical work in different lepidopteran species and (b) predict an important role of learning in lepidopteran agricultural pests.