Technical data
Loop Rolling
3-47
The generated code for this example is:
/* Gain Block: <Root>/Kp */
 {
 int_T i1;
 real_T *u0 = &rtB.Constant1[0];
 real_T *y0 = &rtB.Kp[0];
 for(i1 = 0; i1 < 100; i1++) {
  y0[i1] = u0[i1] * rtP.Kp.Gain;
 }
rtB.Kp[100] = rtB.Constant2[1] * rtP.Kp.Gain;
rtB.Kp[101] = rtB.Constant2[0] * rtP.Kp.Gain;
 u0 = &rtB.Constant3[0];
 y0 = &rtB.Kp[102];
 for(i1 = 0; i1 < 11; i1++) {
  y0[i1] = u0[i1] * rtP.Kp.Gain;
 }
 }
Note that %roll requires rollVars to be specified. The rollVars variable tells 
the loop roller which variables to set up within the roll scope. Note that in this 
case 
P was not declared despite the fact it was specified. This is because it is a 
scalar value, hence, it need not be declared.
As you can see the 
%roll degenerates to %foreach when the code doesn’t roll. 
Thus, you should write the TLC code assuming the 
%foreach case. That is, 
don’t special case your code to handle both cases, rather, write the code once 
RollRegion 1
RollRegion
s
2 & 3
RollRegion 4










