President Mohammed Zia ul-Hag today refused to rule out the possibility that Pakistan will join the nuclear club by setting off an atomic explosion, but he insisted this would be done only if it is needed as part of the country's search for peaceful nuclear power.

Yet he repeatedly stated during a news conference here that "there is no such thing as a peaceful nuclear explosion."

Asked if he would state Pakistan would not set off a nuclear explosion, Zia told closing my options. I will say no comment."

Later, in answer to the same question, he said, "No, no. Not quite. But the fact should remain that we said our program is entirely directed toward nuclear sources of energy and not toward the making of any nuclear bombs.

"If in the process," he continued, "steps have to be taken, we will take them." Diplomatic sources said the comments were the strongest he has made to date on the possibility of a nuclear explosion.

Zia's comments today appeared likely to further fuel an international controversy over the direction of Pakistan's nuclear program.The United States and other Western nations have said it is aimed at the development of atomic weapons, while government officials here insist that oil-starved Pakistan needs atomic power to gain energy self-sufficiency.

According to U.S. intelligence experts, Pakistan will be capable of exploding a nuclear device in three to five years. Such a development would mean that the two strongest nations the South Asian subcontinent, India and Pakistan, would be capable of making nuclear weapons.

Although relations between the two nations -- which were united until 32 years ago as part of the British Raj -- currently are at a high point, India and Pakistan have fought three wars since they gained independence in 1947. U.S. officials fear that adding Pakistan to the nuclear club will have a further destabilizing effect on the already volatile subcontinent.

Moreover, a Pakistani nuclear explosion would make it that much harder for the United States to control the spread of nuclear weapons throughout the world.

Once restricted to the United States alone, the nuclear club soon grew to include the Soviet Union, Great Britain, France and China. India exploded its nuclear device in 1974, a move believed to be the major impetus for Pakistan's current efforts. If U.S. intelligence reports are correct, South Africa may have become the seventh nation to set off an atomic blast.

Israel has not exploded a nuclear device, but most experts believe it too has the capability to do so.

The United States cut off all economic and military aid to Pakistan last April, because of strong belief in Washington that this country was in the midst of an atomic weapons development program.

Although Pakistan has continued to deny that its nuclear program is aimed at weapons development, U.S. Secretary of State Cyrus Vance earlier this month told a high level Pakistani diplomatic delegation in Washington that nothing has happened to change U.S. opinion and that there will be no more American aid until Pakistan backs off.

Zia dismissed the sharp disagreements between the United States and Pakistan as merely a difference of opinion between friends that can be settled by further talks.

"Our program is entirely devoted to producing nuclear energy, not weapons," he insisted.

u.S. experts, however, said that a uranium enrichment facility that Pakistan is building at a cost of several hundred million dollars near the town of Kahuta, 25 miles from here, is not justified by its nuclear energy program. The enrichment plant will produce much more fuel than Pakistan's planned atomic power stations can use, experts said.

American officials are worried because the uranium enrichment plant could turn out nuclear material that can be used for atomic weapons as well as fuel.

Pakistan has only one reactor, built by Canadians near Karachi, but it was shut down this spring "because they [the Pakistanis] couldn't get the nuts and bolts to make it run," a foreign observer said.

While the government has approved construction of a nuclear power plant at Chashma, near Mianwali 150 miles southeast of here, it could take as long as six years to build.

Zia, however, told correspondents Pakistan would have the reactor capacity to use the enriched uranium the plant would produce.

"It is a question of opinion as to whether our program and process is right or wrong. That is debatable," he said, leaving no doubt that he believes Pakistan has chosen the correct path."

Talking about explosions of nuclear devices, Zia said "all explosions are as peaceful as you make them or as nonpeaceful as you make then . . . It is a two-edged weapon.

"In my opinion," he said, "there is no such thing as a peaceful explosion. All explosions can be taken to nonpeaceful measures."

He added that India said its 1974 explosion was for peaceful purposes, but that later "we discovered it was one step toward acquiring a nuclear weapon."

There is no indication that India has developed nuclear weapons, although most experts believe it can if it wants to.

Even if Pakistan explodes a nuclear device, it would still have a long way to go to convert this into a deliverable weapon. Some experts believe that Pakistan would be satisfied merely to set off an explosion, which would put this county on a par with India, and would not want to go any further with weapons developement.