Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
A loop inside another loop. The inner loop completes all its iterations for each single iteration of the outer loop. Time complexity is typically O(n²).
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
cout << matrix[i][j] << " ";
}
cout << endl;
}for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++)
cout << "* ";
cout << endl;
}
// *
// * *
// * * *2 nested loops = O(n²), 3 nested = O(n³). For n=10⁵, O(n²) ≈ 10¹⁰ operations — far too slow. Always check constraints before nesting.