Why is sum i + 1 in question 3
Course: Learn C from Scratch - Learn Interactively
Lesson: Quiz Yourself on Control Flow - Learn C from Scratch
Why is sum i + 1 in question 3
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