This paper proposes a feedback law capable of swinging up and stabilizing the cartpendulum system. The approach uses an iterative algorithm that is typically used to construct a locally linearizing output for nonlinear control-affine systems. However, rather than computing the linearizing output, the algorithm iteratively constructs an approximate feedback form of the original system. The resulting feedback law has a large domain of attraction, which however does not extend over the upper half circle of the pendulum plane. A larger domain of attraction can be obtained by sampling the input and keeping it constant during a short sampling interval. The performance of the strategy is illustrated both in simulation and experimentally on a laboratory-scale setup.