Loops

While and for loops

Integer array loops

#include <iostream>
using namespace std;

int main(){
    int a[4] = {11,22,33,44}; //initialization list

    for (int x =0; x < 4; x++)
        cout << a[x] << endl;

    for (auto x: a)
        cout << x << endl;

    return 0;
}

C string array loops

#include <cstring> //for strlen
#include <iostream>
using namespace std;

int main(){
    char s[12]="Hello World";
    cout << s << endl;

    for (int x =0; x < strlen(s); x++)
        cout << s[x];

    cout << endl;

    for (auto x: s)
        cout << x ;

    cout << endl;
    return 0;
}