0

I do not understand the difference between using for with {} and without {}

As input I used 4 Correct one - https://code.sololearn.com/cIEFJ2Gv1vhO/?ref=app Wrong one - https://code.sololearn.com/czYr0XQ6egSx/?ref=app

22nd May 2021, 9:45 AM
Spake
Spake - avatar
4 Respostas
+ 2
{} enclose the code wich run at each iteration... without {} only the folliwing statement run at each iteration: so, in your codes, with {} you print sum at each iteration, while without, you only print the final value ^^
22nd May 2021, 9:55 AM
visph
visph - avatar
0
visph Ok, thank you for your answer, I will mark this question as answered in 1 hour. Because I want to hear what the others would say.
22nd May 2021, 9:58 AM
Spake
Spake - avatar
0
You got answer already by @visph. Others will also answer same. For clarity you can check code by using Console.WriteLine(sum); instead of Console.Write(sum); in your code.
22nd May 2021, 10:18 AM
Jayakrishna 🇮🇳
0
With {}, Execute all statements within it. Without {}, Execute only first statement.
22nd May 2021, 10:19 AM
Vadivelan