Is there special purpose for using .each() ??

Is there special purpose for using .each() ??

we can also use this....

  1.     $( "li" ).addClass( "foo" );

**so why to use this **

  1.     $( "li" ).each(function() {
  2.       $( this ).addClass( "foo" );
  3.     });