Iterate through fields

In CTL2, I’m trying to loop through fields and reference them somewhat dynamically like this:

metadata0 myrec;
integer fcount;
fcount = length(myrec);
printLog(info, fcount);
for(integer i=0; i<fcount;i++)
{
printLog(info, $0.i);
}

It complains about ‘i’ not being an input metadata field. It’s a variable. I can printLog(info, $0.1) and it works. How can I use variables in the same way? Or, is there a different way to loop through the fields to process their values?

Unfortunately iteration over the record is not possible in CTL2 (see https://bug.javlin.eu/browse/CL-1396 with credentials guest/guest), but you can do it in CTL1 (see Accessing Data Records and Fields).