Forward propagate for any number of layers.