do u guys really understand nested loops? I am having hard time with them. Ex: for foo, inside it, for foo2 inside that, for foo 3. damn
For example, this is a demo for two-nested-loop C program.
#include <stdio.h>
int main() {
const char* A[] = {"♠️", "♥️", "♣️", "♦️"};
const char* B[] = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
const size_t lenA = sizeof(A) / sizeof(A[0]);
const size_t lenB = sizeof(B) / sizeof(B[0]);
for (int i = 0; i != lenA; ++i) {
for (int j = 0; j != lenB; ++j) {
printf("%s%s ", A[i], B[j]);
}
puts("");
}
return 0;
}
It gives you the Cartesian Product of array A and B. For elements in the result of A × B, the code prints it out, and of course you could do anything on the elements to replace printf.
That's why I say nested loops represent Cartesian Product mathematically.