That example is definitely NOT the way linear regression is typically done, but I suppose it is an algorithm to find a regression line. As other answers have correctly stated, there is a closed form solution for finding the Least Squares Regression equation for a set of points.
That being said, what's being shown in the snippet is a method for algorithmically finding a line that gets close to the points by trial and error (i.e. iterations).
As a simple analogy to show the difference between a closed form solution and an algorithm: if I were to give you a mathematical equation, say $10 = 2x+4$, and asked you to solve for $x$, we know that you can solve this exactly using algebra.
$10 = 2x+4$
$\implies 2x=6$
$\implies x=3$ ** Exact solution **
Alternatively, an algorithmic approach to this could be used to solve this same equation by guessing a solution (e.g. start with a random guess: $x=0$) and systematically adjusting $x$ until your condition (statement of equality) is met, or approximately met.
$x = 0 \implies 10=4$ ** too low, adjust up **
$x = 1 \implies 10=6$ ** too low, adjust up **
$x = 2 \implies 10=8$ ** too low, adjust up **
$x = 3 \implies 10=10$ ** condition met, stop **
As this crude example shows, algorithms can sometimes approximate the answers returned by closed form solutions, but this isn't guaranteed to happen for all types of equations.
Personally, I don't find the snippet in the question to be pedagogically helpful to showing how regression lines work, and I think there are better examples of how algorithms can be used to find approximate solutions to mathematical equations.