The US stock market is swinging between losses and gains as uncertainty continues about how long the war with Iran will last.