If you want something along the lines of $(-1)^n$
(which produces $1,-1,1,-1,\ldots$),
first consider
$$ f_1(n) = \tfrac12\left(1 - (-1)^n\right),$$
which implies that $f_1(n) = 0,1,0,1,\ldots$ for $n = 0,1,2,3,\ldots.$
Example 1
We can slow down the rate of alternation of $f_1$
by making the exponent grow slower:
$$ f_2(n) = \tfrac12\left(1 - (-1)^{\lfloor n/2\rfloor}\right),$$
where $\lfloor n/2\rfloor$ is the greatest integer less than or equal
to $n/2.$ This function follows the pattern
$f_2(n) = 0, 0, 1, 1, 0, 0, 1, 1,\ldots$ for $n=0,1,2,3,4,5,6,7,\ldots.$
Put this together in the form $f(n) = f_1(n) + 2f_2(n)$ and you have the function you asked for. That is, let
$$
f(n) = \tfrac32 - \tfrac12(-1)^n - (-1)^{\lfloor n/2\rfloor}.
$$
Example 2
If you don't like the greatest-integer function
(used in the expression $\lfloor n/2\rfloor$), we can work around this
by fiddling with sinusoidal functions.
Let $g_1(n) = \cos\left(\frac12 n\pi - \frac14\pi\right),$ so that
$\newcommand{s}{\frac{\sqrt2}{2}}
g_1(n) = \s,\s,-\s,-\s,\s,\s,-\s,-\s,\ldots$
for $n=0,1,2,3,4,5,6,7,\ldots.$
Then let
\begin{align}
f(n) &= f_1(n) + 1 - \sqrt2g_1(n) \\
&= \tfrac32 - \tfrac12(-1)^n
- \sqrt2\cos\left(\tfrac12 n\pi - \tfrac14\pi\right).
\end{align}
Example 3
If you're willing to use complex numbers, notice that
$\cos z = \tfrac12\left(e^{iz} + e^{-iz}\right).$
Using the function notation $\exp(z) = e^z$ to make the first equation below more readable, we get
\begin{align}
\cos\left(\tfrac12 n\pi - \tfrac14\pi\right) &=
\tfrac12 \left(\exp\left(i\left(\tfrac12 n\pi - \tfrac14\pi\right)\right)
+ \exp\left(-i\left(\tfrac12 n\pi - \tfrac14\pi\right)\right)\right)\\
&= \tfrac12 \left(e^{in\pi/2} e^{-i\pi/4} + e^{-in\pi/2} e^{i\pi/4}\right)\\
&= \tfrac12 e^{i\pi/4} \left(e^{in\pi/2} e^{-i\pi/2} + e^{-in\pi/2}\right).
\end{align}
Then, using the facts that $e^{i\pi/2}=i,$ $e^{-i\pi/2}=-i,$
and $e^{i\pi/4}=\tfrac{\sqrt2}{2}(1+i),$
\begin{align}
\cos\left(\tfrac12 n\pi + \tfrac14\pi\right)
&= \tfrac12\left(\tfrac{\sqrt2}{2}(1+i)\right)\left(i^n(-i)+(-i)^n\right)\\
&= \tfrac{\sqrt2}{4}(1+i) \left((-1)^n - i\right) i^n.
\end{align}
It follows that
$$
f(n) = \tfrac32 - \tfrac12(-1)^n - \tfrac12(1+i)\left((-1)^n - i\right)i^n.
$$
And indeed the right-hand side is also equal to
$\tfrac32-\tfrac12(-1)^n-\tfrac12(1+i)(-i)^n-\tfrac12(1-i)i^n,$
an expression that was given in a comment under another answer.
Frankly, I think any of the preceding examples is far clumsier than Ethan Bolker's formula $n - 4 \lfloor n/4 \rfloor,$ which is inspired by modular arithmetic but actually uses only ordinary integer arithmetic with the
greatest-integer function.
That answer gets my vote.
Example 4
I have added this example after seeing that the accepted answer uses
a curly bracket with multiple cases ($n$ odd and $n$ even)
on the right-hand side of the equation.
If two cases are OK, why not four? That is,
$$
f(n) = \begin{cases}
0 \quad & n = 4k, k \in \mathbb Z \\
1 & n = 4k+1, k \in \mathbb Z \\
2 & n = 4k+2, k \in \mathbb Z \\
3 & n = 4k+3, k \in \mathbb Z \\
\end{cases}
$$