+ 1

(Solved)Sololearn question that I dont understand.

I need to writte the output of: For (n=1; n<10; n+=2) Console.Write(n); And the answers says that is 13579, how?

13th Jul 2020, 3:15 PM
Ángel(🇪🇸)
3 odpowiedzi
+ 4
in first iteration value of "n" is 1 and that is what printed first. After that value of "n" is increased by 2 on every step and is printed without any space between them Thus the answer 13579.
13th Jul 2020, 4:21 PM
Arsenic
Arsenic - avatar
+ 2
1° iteration n=1//output 1; n=1 2° iteration n = n+2//output 3; n=3 3° iteration n = n+2 //output 5;n=5 4° iteration n = n+2// output 7;n=7 5° iteration n = n+2//output 9 n=9 However 6° iteration n = n+2 // n=11; (n is not smaller 10) and the loop end.
13th Jul 2020, 4:21 PM
Coder 97
Coder 97 - avatar
+ 1
Omgggg, I understand now, I throught that its was Console.WriteLine, not just "Line", I should had paid more attention, my bad 😣, thanks both for your help! 🙇
13th Jul 2020, 5:06 PM
Ángel(🇪🇸)