Below is a function that was included in the class I am using to perform operations on matrices. The function returns a boolean value, the first IF statement if NOT TRUE, it returns a value of false, so I assume once it returns this value the rest of the function doesn't execute because it has already returned a value.
If I had written the function I would have included the FOR loop inside an ELSE construct appended to the original IF statement. I'm not a professional programmer so I apologize if the answer is obvious, I just would not have written the code this way and I'm curious if changing all the functions written this way is worth it.
public bool IsIdentityMatrix()
{
if (!this.IsSquareMatrix())
{
return false;
}
for (int i = 0; i < this.RowCount; i++)
{
for (int j = 0; j < this.ColumnCount; j++)
{
decimal checkValue = 0;
if (i == j)
{
checkValue = 1;
}
if (mInnerMatrix[i, j] != checkValue)
{
return false;
}
}
}
}