J.C. Penney Co. took another step away from the brink Thursday, when it reported higher sales, wider margins and a smaller quarterly loss.

Penney, which had lost more than $2.7 billion since early 2012, reported another loss of $172 million. But that result, for the quarter ended Aug. 2, was better than the $586 million loss a year earlier, and the company said its cash flow has improved faster than expected.