User blog comment:Upquark11111/An Explanation of Loader's Number/@comment-11227630-20180116155142/@comment-26454151-20180120040509

It is possible to make a for loop in CoC. You can define the Loop type as $$\Pi A:\ast. (\mathrm{Nat} \rightarrow A \rightarrow A) \rightarrow A \rightarrow A$$. That is, it takes a function that does something different based on what Nat number you give it (this function acts as the "body" of the for loop). You can then define "successor for loops" by adding another layer of function application. From there, it should be easy to define factorials. Note that the way we defined our Loop guarantees its termination.

As for retrieving the nth prime number, I haven't looked into it yet. I know that if you could program a primality test in λPω, then you could use that to generate the nth prime number as follows:

There exists upper bounds for gaps between primes. So, let's define a function that generates the next prime number after a given natural number n. We first generate a Loop of length G(n), where G(n) is an upper bound for the amount of consecutive composite numbers above n. Then, as the body of the Loop, we have a function f(i,x) = x when x is prime, otherwise n+1+i. So, the return value continues to be incremented until it reaches the next prime. Once it does, it stays constant as that prime until the end of the Loop.

Now, to generate the nth prime number, just iterate nextPrime n times on the number 1.