How to loop animation from code?

Need to make animation looping (without setting looping from editor).
animation.play(“walk”); - but it’s not looping

And here is a good solution 5 years later in unity 5:

 this.GetComponent<Animation>()["Walking"].wrapMode = WrapMode.Loop;
//Walking is just the name of the animation

animation.wrapMode = WrapMode.Loop;

Please check the documentation before posting a question.