How can I use foreach inside a code in NetLogo?

In order to create turtles with all profile and R and M combinations, but also let the patches, the turtles get placed on be one-of the turtles profile, you can just reassign the patch's habitatcover. They are chosen randomly before, so it doesn't change anything about the randomness.

Just add

ask one-of AvailablePatch
          [ 
            set habitatcover one-of this-profile
            if habitatcover = 1 [set pcolor 25]
            if habitatcover = 2 [set pcolor 65]
            if habitatcover = 3 [set pcolor 23]
            if habitatcover = 4 [set pcolor 53]
            if habitatcover = 5 [set pcolor 105]
            
            ;...
          ]

to the code I gave you in the other answer.