Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

nested loop c++

#include <iostream>
using namespace std;

int main() {
    int weeks = 3, days_in_week = 7;

    for (int i = 1; i <= weeks; ++i) {
        cout << "Week: " << i << endl;

        for (int j = 1; j <= days_in_week; ++j) {
            // break during the 2nd week
            if (i == 2) {
                break;
            }
            cout << "    Day:" << j << endl;
        }
    }
}
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #nested #loop
ADD COMMENT
Topic
Name
1+2 =