Create a matrix from the rows of another, and calculate the rank of the new matrix

You can also use Minors to get all square sub-matrices of desired dimensions:

minors = Join @@ Minors[X, 3, Identity];
mr2minors = Select[MatrixRank@# == 2 &]@minors;

Row[MatrixForm /@ mr2minors] 

enter image description here

List all 3X3 minors and highlight the ones with rank 2:

Grid @ Partition[MatrixForm /@ minors /. 
   a : MatrixForm[Alternatives @@ mr2minors] :> Highlighted @ a, 7]

enter image description here


This is a slightly different approach from what you asked, but still produces the wanted result. I won't use a loop, while I will look for all the possible combination "at the same time" (it's not always convenient to use loops in Mathematica).

X = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {1, 1, 0}, {1, 0, 1}, {0, 1, 1}, {1, 1, 1}};

Generate all possible subsets of 3 rows:

subs = Subsets[X, {3}];

define a z value (for example 2):

z = 2;

Find all the combinations of rows that give Rank = 2

Select[subs, MatrixRank[#] == z &]

{{{1, 0, 0}, {0, 1, 0}, {1, 1, 0}}, {{1, 0, 0}, {0, 0, 1}, {1, 0, 1}}, {{1, 0, 0}, {0, 1, 1}, {1, 1, 1}}, {{0, 1, 0}, {0, 0, 1}, {0, 1, 1}}, {{0, 1, 0}, {1, 0, 1}, {1, 1, 1}}, {{0, 0, 1}, {1, 1, 0}, {1, 1, 1}}}

If you want the list of the rank of each subset:

MatrixRank /@ subs

{3, 2, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3}