I came across this code to find prime numbers and I don't quite understand the nested for loop. Can someone explain exactly how it works? If i and j both = 2, then how does j increment when j < i (since 2 isn't less than 2)? Please take a look.
Code:#include <iostream> using namespace std; int main() { int flag = 0; for(int i = 2; i <= 100; i++) { for(int j = 2; j < i; j++) { if( i % j == 0) flag = 1; } if(flag == 0) cout << i << endl; flag = 0; } cin.get(); return 0; }