What is difference between for and for each loop.Please explain with a example.
for loop: Used when you know the number of iterations (uses index). forEach loop: Used to iterate over elements of an array directly (no index control). Example: JavaScript // for loop for (let i = 0; i < arr.length; i++) { console.log(arr[i]); } // forEach loop arr.forEach(function(item) { console.log(item); });