Difference between for loop and foreach loop
- In case of a for loop the loop variable refers to the index of the array whereas In case of foreach loop the loop variable refers to the value of the array.
- In case of for loop the data type of the loop variable is always int only irrespective of the type of value. Whereas in case of foreach loop the datatype of loop variable will be same as the type of values in the array
- By using for we can either access or assign value to an array. Whereas by using a foreach loop we can only access the values but not assign the value.
No comments:
Post a Comment