7th Apr 2019, 9:31 AM
Iqra
8 Respuestas
+ 1
You use all kinds of loops in your own codes, so you seem to understand how they work. Just think about what the loop does, step by step. Where does the loop begin, where does it stop? What happens if i==6? What happens in all other cases?
7th Apr 2019, 9:53 AM
Anna
Anna - avatar
+ 1
But here i have just used (FOR loop)
7th Apr 2019, 9:58 AM
Iqra
+ 1
You use the same kind of loop on this code: https://code.sololearn.com/WCTFt1Mr0ZiK/?ref=app
7th Apr 2019, 9:59 AM
Anna
Anna - avatar
+ 1
If (i<=8)then i=8 will be added to sum and 17 will be printed as output or not??
7th Apr 2019, 10:29 AM
Iqra
+ 1
Ok
7th Apr 2019, 10:36 AM
Iqra
0
The loop will go from i = 4 to 7 In each time it will ask if i = 6. First, at i = 4, the if cond is not executed because it is false and it will just at the value of i to sum (0 + 4) now sum = 4. now next i = 5, sum will be 4 + 5 = 9, At i = 6, the if statement becomes true which will execute the statement "continue;" that will skip all the next statements in the loop at the current i run which will not add any value to the sum. Lastly, i = 7 the if is not executed, i will be added to sum wich will be 9+7=16 next i = 8 the loop's cond is false, the loop will not be executed. The value 16 will be printed which is the value of sum ofcourse. Hope that helped you out. · Sorry for the big explanation :)
7th Apr 2019, 10:05 AM
Alex Schmidt
Alex Schmidt - avatar
0
K i am gettimg u,r logic
7th Apr 2019, 10:11 AM
Iqra
0
No 24 will be printed if the loop's cond was (i <= 8)
7th Apr 2019, 10:32 AM
Alex Schmidt
Alex Schmidt - avatar