Indian shares swung between gains and losses on Friday to close slightly higher but recorded their first weekly decline in three, with investors making positional adjustments ahead of the outcome of the national elections next week.

The NSE Nifty 50 ended up 0.2% at 22,531 points, while the S&P BSE Sensex gained 0.1% to 73,961 points.

Both benchmarks rose as much as 0.7% in early trade before giving up the gains. For the week, they ended 1.9% lower.

India's weeks-long election will conclude on June 1, with the votes being counted on June 4. Investors are awaiting the exit polls, which project results after voting ends.

Also in focus will be India's fourth-domestic quarter GDP data due later in the day, which is expected to show the economy grew at a slower pace than the previous three months.

Benchmarks had fallen for five straight sessions until Thursday and are down 2.4% from an all-time high hit early this week.

Foreign investors have adopted a cautious approach by adding long positions in single stock futures, hedged with additional index shorts in the run-up to election results, said Abhilash Pagaria, Head, Nuvama Alternative and Quantitative Research.

IT stocks were the top drags for the week, falling 4.3% on worries over U.S. interest rates staying higher for longer, hurting client spends.

A clear mandate in the elections would reinforce confidence in India, ensuring policy continuity and positive foreign flows can be anticipated, said Amar Ambani, Executive Director, YES Securities.

Among individual shares, India Nippon Electricals rose 6% and Bharat Rasayan jumped 16% on strong quarterly earnings.

Adani Enterprises and Adani Ports surged 6.8% and 3.9%, respectively and were top Nifty 50 gainers.

(Reporting by Sethuraman NR in Bengaluru; Editing by Janane Venkatraman )