FORT BRAGG, N.C.  — The judge deciding Army Sgt. Bowe Bergdahl's punishment said Monday he is concerned that President Donald Trump's comments about the case could impact the public's perception of the military justice system.

Sentencing for Bergdahl on charges of desertion and misbehavior before the enemy was set to begin Monday, but the judge, Army Col. Jeffery R. Nance, instead heard arguments about a last-minute motion by defense attorneys that recent comments by Trump are preventing Bergdahl from getting a fair sentence. Bergdahl faces life in prison on charges that he endangered comrades by walking off his post in Afghanistan in 2009.

Nance allowed the attorneys to question him on the record about whether he was swayed by Trump's comments. Nance said he was not aware of the comments beyond the legal motions in the case. Nance said he plans to retire as a colonel in about a year and isn't motivated by pleasing commanders to win a future promotion.

"I don't have any doubt whatsoever that I can be fair and impartial in the sentencing in this matter," Nance said.

But he had stern words and pointed questions for prosecutors about what effect Trump's comments would have on the public's perception of the case. He indicated he would issue a written ruling later on the defense request to have the case thrown out over Trump's comments.

On the campaign trail, Trump repeatedly called Bergdahl a "dirty, rotten traitor" who deserved to be executed by firing squad or thrown out of a plane without a parachute. Nance previously ruled that those comments were "disturbing" but didn't amount to unlawful command influence and noted the statements were made before Trump assumed his position at the top of the armed forces' command structure.

But last week Trump addressed his past comments in response to a reporter's question at a news conference. He told reporters he couldn't say anything more about the case, "but I think people have heard my comments in the past." That, the defense, said shows that he still harbors his previous views as commander in chief.

Prosecutors argued that Trump's comments didn't reaffirm his campaign-trail criticism and were narrowly focused on the question a reporter posed.

But Nance said he was having a "hard time" with prosecutors' interpretation, noting public confidence in military courts was something he had to consider.

"The member of the public that we are interested in maintaining confidence in the military justice system ... is going to be influenced by context," he said.

Nance said his interpretation of Trump's most recent comments was tantamount to the president saying: "I shouldn't comment on that, but I think everyone knows what I think on Bowe Bergdahl."

The White House issued a statement Friday that, without mentioning Bergdahl by name, said any military justice case must be "resolved on its own facts." Prosecutors cited that statement in opposing the latest defense arguments.

Sentencing was set to resume Wednesday because a defense attorney was unavailable for part of this week, the judge said.

Bergdahl faces up to life in prison after pleading guilty last week to desertion and misbehavior before the enemy. Prosecutors made no deal to cap his punishment, so the judge has wide leeway to decide his sentence after a hearing expected to take several days.

Nance, is expected to weigh factors that include Bergdahl's willingness to admit guilt, his five years of captivity in the hands of the Taliban and its allies, and the serious wounds that several service members suffered while searching for him.

Prosecutors are expected to put on evidence or testimony about soldiers and a Navy SEAL who were seriously wounded by gunfire during these search missions, including an Army National Guard sergeant who was shot in the head, suffering a traumatic brain injury that put him in a wheelchair, unable to speak.

Bergdahl, 31, from Hailey, Idaho, was captured soon after walking off his remote post in 2009. He has said he was caged, kept in darkness and beaten, and tried to escape more than a dozen times. He said his intention had been to alert other commanders to what he saw as problems with his unit. Still, when he pleaded guilty, he told the judge that his actions were inexcusable.

President Barack Obama brought Bergdahl home in 2014 in a swap for five Taliban prisoners at Guantanamo Bay, saying the U.S. does not leave its service members on the battlefield. Republicans roundly criticized Obama.