878017. For-Each Loop

Basic

Here is the detailed Markdown blog post for the "For-Each Loop" problem:

For-Each Loop

Summary

The problem involves implementing a for-each loop to iterate over a collection of elements. The key concept involved is iteration over a data structure, such as an array or list.

Detailed Explanation

A for-each loop is used to iterate over a collection of elements without the need to manually keep track of an index variable. This type of loop is particularly useful when working with collections like arrays, lists, or maps.

Here's a step-by-step breakdown of the solution:

View on GeeksforGeeks
import java.util.Arrays;

public class ForEachLoop {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 4, 5};
        for (int num : nums) {
            System.out.println(num);
        }
    }
}

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.