To iterate subfile rows you need to know when you have reached the last row in order to stop your logic. To do this use the CHECK_FIELD_EXISTS Function:
for ( Index = 1; CHECK_FIELD_EXISTS("SFL_SEL", Index); Index++ )
{
SETVALUE("SFL_SEL","X", Index);
}where SFL_SEL is any of the named subfile fields (columns).