Traversing a C++ Array

#include <iostream>

int main() {
    const int size = 5;
    int myArray[size] = {10, 20, 30, 40, 50};

    // Traverse the array using a for loop
    std::cout << "Traversing the array using a for loop:" << std::endl;
    for (int i = 0; i < size; ++i) {
        std::cout << myArray[i] << " ";
    }
    std::cout << std::endl;

    // Traverse the array using a while loop
    std::cout << "Traversing the array using a while loop:" << std::endl;
    int j = 0;
    while (j < size) {
        std::cout << myArray[j] << " ";
        ++j;
    }
    std::cout << std::endl;

    // Traverse the array using a range-based for loop (C++11 and later)
    std::cout << "Traversing the array using a range-based for loop:" << std::endl;
    for (int element : myArray) {
        std::cout << element << " ";
    }
    std::cout << std::endl;

    return 0;
}