For the first block, to which there is no previous block output, a Initialization Vector (IV) is used. This number is reused for every call to the hash function, and in practice you can just look it up in a standards document. The last block's output is the result that you return.
Narayanan, Arvind, et al. (2017). Bitcoin and Cryptocurrency Technologies. United States: Princeton Press