did you mean outer squares? That is, on a 100x100, display top two rows, bottom two rows, and the first 2 and last 2 columns?
or something else?
If its what I said, display the top 2 rows in a loop, then the sidebar columns and filled in middle in a loop, and then the last 2 rows. Sure, you can condition it all up to do it in a single loop, but that is more complicated and slower than the 3 loops (conditions take cpu time).
alternately, you can print the whole thing, and replace the innner square with dashes, if you don't mind the conditional.
in that case, if the rows are > 1 (0 and 1 are first 2 rows) and less than maxrow-1 (eg your example 6 rows, -1 is 5, less than 5 is 4,3,2,1,0 but the first part took out 0 and 1 so you mess with rows 4,3,2 only) and similar for columns -- if on valid rows to tamper with, you check that columns are >1 and < maxcol-1 exact same idea.
you are looking at the DATA. you need to look at the INDEX.
M[0][j] && M[1][j]
that says it is true if the data in [0][j] and the data in [1][j] are both nonzero. Nothing like what you want.