When an action is commenced to foreclose a lien by which a debt is secured, which debt is payable in installments either of interest or principal, and any of the installments is not then due, the court shall adjudge a foreclosure of the lien, and may also adjudge a sale of the property for the satisfaction of the whole of the debt or so much of it as may be necessary to satisfy the installment then due, with costs of action. In the latter case the judgment of foreclosure as to the remainder of the property may be enforced by an order of sale, in whole or in part, whenever default is made in the payment of the installments not then due.