August 2018
Intermediate to advanced
380 pages
10h 2m
English
One of the fundamental rules of engineering is to create abstractions for logic that repeats. The pattern of the loop is ubiquitous. You can experience it in almost any program. Hence, it is reasonable to abstract away. This is why contemporary languages, such as Java or C++, have their own built-in mechanisms for loops.
The difference it makes is that, now, the entire pattern consists of one component only, that is, the keyword that must be used with a certain syntax:
#include <iostream>using namespace std;int main() { int rows = 3; int cols = 3; int matrix[rows][cols] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) cout << matrix[r][c] << " "; cout ...