What is difference between for loop and foreach?



What is difference between for loop and foreach?..

Answer / Gorakh Nath Tripathi

For loops are traditional loops used for iterating through a range of values or accessing items in arrays, while foreach loops are optimized for iterating over collections. For loops provide more control with indexes, whereas foreach loops are easier to read due to their syntax for looping through each item.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Data Structures Interview Questions

List the two important key points of depth first search?

1 Answers  


In what data structures are pointers applied?

1 Answers  


How do you insert a new item in a binary search tree?

1 Answers  


How to find if linked list has loop?

1 Answers  


Write a program using mergesort technique.

1 Answers   iNautix,


What are the tasks performed during postorder traversal?

1 Answers  


What is the best time complexity of bubble sort?

1 Answers  


What is the best sorting technique?

1 Answers  


Which is the slowest sorting algorithm?

1 Answers  


How would you check if a binary tree is BST or not ? Write a program.

1 Answers   DELL,


What is a hashmap in c?

1 Answers  


Define depth and height of a tree?

1 Answers  


Categories