An indefinite integral, aka antiderivative, is necessarily a continuous function. If you graph the function $-\cos xsgn(\sin x)$, you'll see that it is discontinuous at the multiples of $\pi$. However, you can make it continuous by adding on the step function $s(x)=2\lfloor x/\pi\rfloor$. More precisely, we have
$$\int|\sin x|\,dx=C+
\begin{cases}
-\cos xsgn{(\sin x)}+2\lfloor x/\pi\rfloor\quad\text{for }x\not\in\pi\mathbb{Z}\\
2\lfloor x/\pi\rfloor-1\quad\text{for }x\in\pi\mathbb{Z}
\end{cases}$$
where $C$ is an arbitrary constant.
Note, it's easy to see that the derivative of this piecewise-defined function is equal to $|\sin x|$ in each interval $k\pi\lt x\lt(k+1)\pi$ with $k\in\mathbb{Z}$, since $sgn(\sin x)$ and $2\lfloor x/\pi\rfloor$ are constant in each such interval. It's a good exercise to verify that the derivative exists, and is equal to $0$, at the multiples of $\pi$.
For the given definite integral, we have
$$\int_0^\pi|\sin x|\,dx=(C+2\lfloor\pi/\pi\rfloor-1)-(C+2\lfloor0/\pi\rfloor-1)=(C+2-1)-(C+0-1)=2$$
which agrees, of course, with the simpler calculation
$$\int_0^\pi|\sin x|\,dx=2\int_0^{\pi/2}\sin x\,dx=-2\cos x\big|_0^{\pi/2}=0-(-2)=2$$
Again, the fallacy lay in thinking that the formula $-\cos xsgn(\sin x)$, which defines a discontinuous function, could serve as "the" indefinite integral for $|\sin x|$.
I copied and pasted this answer, since I actually wrote this answer to a different question which you can find here: Another way to solve $\int \frac{\sin^4(x)}{1+\cos^2(x)}\ dx$ without the substitution $y=\tan\left(\frac{x}{2}\right)$? ).
Define ${S_n = \int\sin^{2n}(x)dx}$. Then
$${S_{n}=\int \sin^2(x)\sin^{2n-2}(x)dx=S_{n-1}-\int \cos^2(x)\sin^{2n-2}(x)dx}$$
On the rightmost integral, using integration by parts yields
$${\int\cos^2(x) \sin^{2n-2}(x)dx=\frac{\cos(x)\sin^{2n-1}(x)}{2n-1}+\frac{1}{2n-1}\int \sin^{2n}(x)dx}$$
So overall
$${\Rightarrow S_n = S_{n-1}-\frac{\cos(x)\sin^{2n-1}(x)}{2n-1} - \frac{1}{2n-1}S_n}$$
And so
$${\left(\frac{2n}{2n-1}\right)S_n = S_{n-1} - \frac{\cos(x)\sin^{2n-1}(x)}{2n-1}}$$
$${\Rightarrow S_n = \frac{(2n-1)S_{n-1}}{2n} - \frac{\cos(x)\sin^{2n-1}(x)}{2n}}$$
Now you have a recursion relation that will help you compute the integral for higher even powers of ${\sin(x)}$:
$${S_{n} = \frac{(2n-1)S_{n-1}}{2n} - \frac{\cos(x)\sin^{2n-1}(x)}{2n}}$$
Best Answer
It equals $$ F(x)sgn(f(x)) + c_k$$ Every time $f(x)$ changes sign, you need a new constant $c_k$ to make up for the jump in $F(x)sgn(f(x))$, so that the whole integral remains continuous. For example, if $f(x)=2x-1$, then $F(x)=x-x^2+c$ when $x<1/2$, but $x^2-x+c+1/2$ when $x\geq1/2$.