President Obama told Jay Leno during his visit to the Tonight Show Tuesday that you never like to see anybody come to the kind of end that Muammar Gaddafi did, but that his death sends a message to other dictators.

Obama -- who appeared smiling and confident as he made the second visit of any sitting president to The Tonight Show -- also said he hasn't paid much attention to the GOP debates so far. In an interview that bounced between serious issues and just connecting with the audience, he also joked about what Michelle Obama is giving trick-or-treaters for Halloween.

Obama won over the studio audience with can't-miss praise of U.S. troops, and avoided any gaffes like the one that marred the first Tonight Show appearance of his presidency. In March 2009, he had to apologize for jokingly comparing his bowling abilities to those of Special Olympics athletes.

Leno unsurprisingly devoted the entire interview segment of the show to the president. He started somberly, asking Obama about Gaddafi's death.

Well, this is somebody who, for 40 years, has terrorized his country and supported terrorism, the president responded. And he had an opportunity during the Arab spring to finally let loose of his grip on power and to peacefully transition into democracy.

We gave him ample opportunity, and he wouldn't do it. And, obviously, you never like to see anybody come to the kind of end that he did, but I think it obviously sends a strong message around the world to dictators that people long to be free, and they need to respect the human rights and the universal aspirations of people.

Video of the bloodied Libyan dictator being dragged away -- and later shots of his corpse being surrounded by crowds -- appeared worldwide last week. Leno asked for Obama's thoughts about the mob mentality that possessed the rebels who captured Gaddafi.

Obviously that's not something that I think we should relish. There was a reason after [Osama] bin Laden was killed, for example, we didn't release the photograph. I think that there's a certain decorum with which you treat the dead even if it's someone who has done terrible things.

He also defended the U.S. strategy in Libya, which included establishing a no-fly zone and coordinating NATO operations.

We were able to organize the international community, he said. That's part of the reason why this whole thing only cost us a billion dollars, as opposed to a trillion dollars. Not a single U.S. troop was on the ground. Not a single U.S. troop was killed or injured.

The comment was the first to earn him the audience's applause. He scored more seconds later when he praised the Navy Seal team that killed bin Laden.

It could have been a disaster, he said. Even though it was 50/50 that bin Laden would be there, I was 100 percent confident in them. I could not have made that decision were it not for the fact that our men and women in uniform are the best there is.

He praised the troops again -- as well as their families -- as he explained what the U.S. had accomplished in Iraq. He was again awarded with audience applause.

He expressed deadpan surprise at Republican opposition to the U.S. withdrawal from Iraq.

It's shocking that they opposed something I proposed, he said.

Other applause lines included his praise of Secretary of State Hilary Clinton, his call for bipartisanship in improving the U.S. domestically, and his suggestion that improving Los Angeles roads could be one way to create jobs. He also rejected speculation that Vice President Biden and Clinton could swap jobs.

I think that they're doing great where they are, he said.

He concluded with light banter about exercise, the Republican presidential candidates, and a visit Monday night to Los Angeles restaurant Roscoe's Chicken and Waffles. He described the fancy presidential limousine smellin' like chicken, to the cheers of the audience.

He said his wife is okay with eating junk food in moderation -- and joked that the White House will get egged if she doesn't give trick-or-treaters candy at Halloween.

He also said he isn't paying close attention to the Republican presidential debates.

I'm going to wait until everybody is voted off the island before -- he joked about the race, trailing off before finishing the thought. Once they narrow it down to one or two, I'll start paying attention.