why is sum 1 16, it breaks when it is 15, it shouldn’t run the loop again
Course: Learn C from Scratch - Learn Interactively
Lesson: Quiz Yourself on Control Flow - Learn C from Scratch
why is sum 1 16, it breaks when it is 15, it shouldn’t run the loop again
Course: Learn C from Scratch - Learn Interactively
Lesson: Quiz Yourself on Control Flow - Learn C from Scratch
Hi @A_Huang, Thanks for reaching out to us.
The sum1 variable used in the program gives a value of 16 because there is a break statement that says
if(i + 5 >= 20){ break; }
, which means the loop will break when the value of ‘i’ is greater than or equal to 15.
In for loop value of ‘i’ starts from 0 as shown in the code for(int i = 0; i <= 20; i++)
so from 0-15, the total values become 16 because we have to include 0 as well.
Hope it will clear your confusion, Happy Learning