U.S. stock indexes ticked lower on Thursday, but only after a circuitous ride that saw them flip multiple times between small gains and losses.

Food companies struggled after the makers of Spam and Folgers coffee reported weaker-than-expected results, and grocers fell after Amazon said it plans to cut prices for avocados, eggs and other products when it takes control of Whole Foods next week. Retailers were big winners after a wide variety said they earned fatter profits last quarter than Wall Street forecast.

advertisement | advertise on newsday

The Standard & Poor’s 500 index fell 5.07 points, or 0.2 percent, to 2,438.97.

The Dow Jones industrial average fell 28.69 points, or 0.1 percent, to 21,783.40, the Nasdaq composite fell 7.08 points, or 0.1 percent, to 6,271.33 and the Russell 2000 index of small-cap stocks rose 4.14 points, or 0.3 percent, to 1,373.88.

The market has drifted up and down since the S&P 500 set a record high earlier this month. Helping stocks has been strong growth in profits.

Hurting stocks have been worries about politics both in Washington and abroad. Doubts are rising about how much help the Republican-led White House and Congress can provide for businesses. Several crucial deadlines are coming up that could damage the economy, including a vote to avoid a default on the national debt, though most investors expect calamity to be averted.