THANKS FOR YOUR CONCERN!!!!
The full code is (this full code is basically to check the equality of matrices)
:
:
void main();
{ clrscr();
int A[3][3],B[3][3],r,c;
cout<<"1st matrix rowwise";
:
:
for(r=0;r<3;r++)
{ for(c=0;c<3;c++)
{cin>>B[r][c];
}// loop to check equality
int flag=0;
for(r=0;r<3;r++)
{for(c=0;c<3;c++)
{if(a[r][c]!=B[r][c])
{flag=1;break;} //The part where my doubt starts
}
if(flag==1) break ; // this whole thing till end
}
if(flag)
cout<<"matrices r unequal ";
else
cout<<"matrices are equal";
}
void main();
{
clrscr();
int A[3][3],B[3][3],r,c;
cout<<"1st matrix rowwise";
:
:
for(r=0;r<3;r++)
{
for(c=0;c<3;c++)
{
cin>>B[r][c];
}
// loop to check equality
int flag=0;
for(r=0;r<3;r++)
{
for(c=0;c<3;c++)
{
//The part where my doubt starts
if(a[r][c]!=B[r][c])
{
flag=1;
break;
}
}
if(flag==1) break ; // this whole thing till end
}
if(flag)
cout<<"matrices r unequal ";
else
cout<<"matrices are equal";
}
}
OK, so flag is used like a Boolean, either true or false. Basically it is set to 0 (false) and then the program starts scanning through arrays 'a' and 'B', if a mismatch is found then flag is set to 1 (true) and the loops break out.
Summed up, flag is used to break out all of the loops and retain the status of the match, if false (0) no mismatches were found, if true (1) mismatches were found.
Does this make sense now?
I'll recode it a little to make it more intuitive: