well...i don't understand how the nested looping work...can anyone explain clearly for me??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
usingnamespace std;
int main()
{
for ( int i = 4 ; i >0 ; i--){
for ( int j = i ; j < 4 ; j++){
cout<<" ";
}
for( int j = i ; j >0 ; j--){
cout<<j;
}
cout<<endl;
}
return 0;
}
and the output is
4321
321
21
1
why it will become like that? my lecturer didn't explain well for me...
nested loops are not really a new concept. If you understand how a single loop works, then you can understand how nested loops work. The inner loops are just another code segment that is looped.
To understand that code you posted, simply walk through it.