Need help with these codes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Need help with these codes

Can anyone explain the difference between code1 and code2 in https://code.sololearn.com/WYqYYBZ3gh2j/?ref=app and why is the output so much different when you just change the place of a curly brace?

10th Jan 2021, 5:06 AM
★_★_★
★_★_★ - avatar
3 Answers
+ 4
the first code u write 'i' for every loop, then write 'now i..' after the loop end once when i become 6..so output 1 2 3 4 5 now i = 6 the second code u write 'i' and 'now i..' for every loop..it should looks like this 1 now i = 1 2 now i = 2 3 now i = 3 4 now i = 4 5 now i = 5 but since u didnt put newline after 'now i',it is mixed 1 now i = 12 <-- 2 here is actually the start of second loop
10th Jan 2021, 5:30 AM
durian
durian - avatar
+ 5
Lily Mea yes correct. I was going to write the same.🙂. It just concat the output. https://code.sololearn.com/Wlqw8XnDPNsf/?ref=app
10th Jan 2021, 5:31 AM
P∆WAN M∆URY∆
P∆WAN M∆URY∆ - avatar
+ 3
Lily Mea and P∆WAN M∆URY∆ Thanks for clearing up misunderstandings
10th Jan 2021, 5:47 AM
★_★_★
★_★_★ - avatar