An unlikely ally in the war on childhood obesity is the school vending machine. That is, if it's stocked with fruits and vegetables.

But many of them are not.

Researchers looked at the food sold in vending machines at 152 schools and the dietary behaviors of 5,930 students.

They found the diets of children are influenced by vending machines in their schools, possibly affecting their overall dietary intake and health, depending on what foods they contain.

Younger children are the most influenced by the contents of their schools vending machines.

The study also found the overwhelming majority of school vending machines -- a whopping 83 percent -- sold foods having minimal nutritional value, such as sodas, sweets and chips.

"The most salient point is that we link school vending machine content to student diet," said study coauthor Ronald Iannotti, Ph.D., at the Eunice Kennedy National Institute of Child Health and Human Development, part of the National Institutes of Health.

The researchers found children were easily swayed to eat healthier if given the option.

"In elementary schools and middle schools that sell fruits and vegetables in vending machines, students consumed more [produce] than those from schools in which vending machines did not offer such choices," Iannotti said.

The researchers found the same relationship between schools that sell sweets in vending machines and overall sweets consumption.

The study, published online in the Journal of Adolescent Health, is the first to differentiate the effects of vending machines in elementary and middle schools from high schools and is the first to examine the topic with a nationally representative sample, the authors say.

"We are supposed to be teaching proper nutrition in the schools and having a vending machine inside of the school doesn't make sense," said Joel Fuhrman, M.D., a board certified family physician and nutritional researcher who specializes in preventing and reversing disease. "Schools are introducing foods that every nutritional scientist in the world knows are dangerous."

Fuhrman said that, according to the World Health Organization, the effects of poor dietary choices on morbidity and mortality -- and the associated health care costs -- now surpass those of smoking cigarettes and taking illegal drugs combined.

"Schools provide not only an environment for learning but an environment that affects healthful eating and physical activity," Iannotti said. "School policies should require the establishment of an optimum environment for child health."