  An efficient algorithm is presented to simulate the O(N) loop model on the
square lattice for arbitrary values of $N>0$. The scheme combines the worm
algorithm with a new data structure to resolve both the problem of loop
crossings and the necessity of counting the number of loops at each Monte Carlo
update. With the use of this scheme, the line of critical points (and other
properties) of the O($N$) model on the square lattice for $0<N\le 2$ have been
determined.
