user10793: I'm trying to make a loop from an animated mask, but each time I introduce my loop expression: loopOut (type="cycle", numKeyframes = 0), After Effects is telling me that:

"Expression is deactivated, because of line 1 and that the layer doesn't allow loop"

I have tried to use the pre-expressions from the application, but it still doesn't work:

What I'm doing wrong or what else can I do to loop the mask?

user17789: if (numKeys >1 && time > key(numKeys).time){
  t1 = key(1).time;
  t2 = key(numKeys).time;
  span = t2 - t1;
  delta = time - t2;
  t = delta%span;
  valueAtTime(t1 + t)
}else
  value

courtesy of the Master Expressionist Dan Ebberts in this thread:
https://forums.creativecow.net/thread/227/20661#22869

user1950: Another option if you don't want to create a pre-comp:
Make your mask and set the keyframes and apply this expression to the mask path property:
valueAtTime(time % key(numKeys).time)

This is basically an implementation of the loopOut function, but it works for all properties, including custom ones like mask shapes.

How it works: valueAtTime returns the value of the property at a given time, so to loop the property we need a value that goes from 0 and rises until the playhead gets to the last keyframe and then the value loops back to 0. 
The expression key(numKeys).time returns the time of the last key (e.g. if there are 3 keys it will be key(3).time). The % operator is the modulus operator, which gives you the remainder when you divide the first term by the second. So if you find the remainder when dividing the current time (time) by the time of the last keyframe it will return a value that starts at 0 and rises in synch with time until the playhead reaches the last keyframe at which point the current time will divide exactly into the time of the last keyframe, so the remainder will go back to 0 then start rising in synch with the playhead, rinse, repeat. 
A useful feature of this expression is that you can speed it up and down by multiplying time by another factor, e.g. time * 2 % key(numKeys).time would play back the animation in double speed.

user6685: This expression is not supported for Mask Path Property, because it's a User Defined Property, see the note of the error message. 
Workaround

Mask Path animation once

Precompose your layer an with the animated mask (one time) by Selecting the Layer > Right Click > Precompose (and move all attributes in the new composition)
Enable Time Remapping on your new created composition (Right Click on the composition > Time > Time Remapping), this extends the length of the layer to infinity
Add loopOut(type="cycle") expression to the Time Remapping Property by holding Alt and clicking the stop watch left beside the properties name


Time Remapping enabled on the new composition and expresssion applied
Example

Example using 3 keyframes (third is same as first) and using loopOut() only

10793: <p>I'm trying to make a <strong>loop from an animated mask</strong>, but each time I introduce my loop expression: <code>loopOut (type="cycle", numKeyframes = 0)</code>, After Effects is telling me that:</p>

<blockquote>
  <p>"Expression is deactivated, because of line 1 and that the layer doesn't allow loop"</p>
</blockquote>

<p>I have tried to use the <strong>pre-expressions</strong> from the application, but it still doesn't work:</p>

<p><img src="https://i.stack.imgur.com/mo9XA.png" alt="enter image description here"></p>

<p>What I'm doing wrong or what else can I do to loop the mask?</p>
 17789: <pre><code>if (numKeys &gt;1 &amp;&amp; time &gt; key(numKeys).time){
  t1 = key(1).time;
  t2 = key(numKeys).time;
  span = t2 - t1;
  delta = time - t2;
  t = delta%span;
  valueAtTime(t1 + t)
}else
  value
</code></pre>

<p>courtesy of the Master Expressionist Dan Ebberts in this thread:</p>

<p><a href="https://forums.creativecow.net/thread/227/20661#22869" rel="nofollow noreferrer">https://forums.creativecow.net/thread/227/20661#22869</a></p>
 1950: <p>Another option if you don't want to create a pre-comp:</p>

<p>Make your mask and set the keyframes and apply this expression to the mask path property:</p>

<pre><code>valueAtTime(time % key(numKeys).time)
</code></pre>

<p>This is basically an implementation of the loopOut function, but it works for all properties, including custom ones like mask shapes.</p>

<p><img src="https://i.stack.imgur.com/tarzg.png" alt="enter image description here"></p>

<p><strong>How it works</strong>: <code>valueAtTime</code> returns the value of the property at a given time, so to loop the property we need a value that goes from 0 and rises until the playhead gets to the last keyframe and then the value loops back to 0. </p>

<p>The expression <code>key(numKeys).time</code> returns the time of the last key (e.g. if there are 3 keys it will be <code>key(3).time</code>). The <code>%</code> operator is the modulus operator, which gives you the remainder when you divide the first term by the second. So if you find the remainder when dividing the current time (<code>time</code>) by the time of the last keyframe it will return a value that starts at 0 and rises in synch with <code>time</code> until the playhead reaches the last keyframe at which point the current time will divide exactly into the time of the last keyframe, so the remainder will go back to 0 then start rising in synch with the playhead, rinse, repeat. </p>

<p>A useful feature of this expression is that you can speed it up and down by multiplying <code>time</code> by another factor, e.g. <code>time * 2 % key(numKeys).time</code> would play back the animation in double speed.</p>
 6685: <p>This expression is <strong>not supported for Mask Path Property</strong>, because it's a <em>User Defined Property</em>, see the note of the error message. </p>

<h3>Workaround</h3>

<p><img src="https://i.stack.imgur.com/0byVw.jpg" alt="enter image description here"></p>

<p><em>Mask Path animation once</em></p>

<ol>
<li><strong>Precompose your layer</strong> an with the animated mask (one time) by <em>Selecting the Layer > Right Click > Precompose</em> (and move all attributes in the new composition)</li>
<li><strong>Enable Time Remapping</strong> on your new created composition <em>(Right Click on the composition > Time > Time Remapping)</em>, this extends the length of the layer to infinity</li>
<li>Add <code>loopOut(type="cycle")</code> expression to the <strong>Time Remapping Property</strong> by holding <kbd>Alt</kbd> and clicking the stop watch left beside the properties name</li>
</ol>

<p><img src="https://i.stack.imgur.com/XDAG9.jpg" alt="enter image description here"></p>

<p><em>Time Remapping enabled on the new composition and expresssion applied</em></p>

<h3>Example</h3>

<p><img src="https://i.stack.imgur.com/XGyhx.gif" alt="enter image description here"></p>

<p><em>Example using 3 keyframes (third is same as first) and using <code>loopOut()</code> only</em></p>
