An N-stage optimal control problem formulated in very general terms is transformed into a nonlinear programming problem by constraining the closed-loop strategies to take on the structure of multi-layer feed-forward neural networks. A nonlinear programming problem results from substitution of the neural strategies in the process cost, which becomes a function of the synaptic weights and of the initial state. The dependence on the initial state is removed by averaging the cost function with respect to the initial state, which is assumed to be a stochastic vector uniformly distributed on a given region. The gradient method is then applied to optimize the synaptic weights by using the stochastic approximation concept. Recursive equations to compute the gradient components in a distributed way are presented, which generalize the adjoint system equations. Simulation results for nonlinear non-quadratic problems show that the method performs efficiently.