1. The loop will be executed 10 times. On each iteration a variable ires will be augmented by 1 starting from 0. So, after all, the value of ires will be 10.
Answer. 10.
2. The loop will be executed 10 times. On each iteration a variable ires will be augmented by the value of index starting from 0. So, after all, the value of ires will be the sum of all digits from 1 to 10, namely, 55.
Answer. 55.
3. The outer loop will be executed 10 times. On each iteration the inner loop will be executed 6-index1 times, namely 5,4,3,2,1 and 0 times and then 10 times after index2 becomes grater then 6. On each inner iteration a variable ires will be augmented by 1. So, after all, the value of ires will be 5+4+3+2+1 + 10 = 25
Answer. 25.
4. The outer loop will be executed 10 times. On each iteration the inner loop would be executed 10-index1 times if there were no following code:
if index2 == 6
continue;
end
In this case the answer would be 55, as far as on each inner iteration a variable ires is augmented by 1. But the variable index2 becomes 6 six times, so we loose 6 iterations. Thus, the value of ires will be 55-6 = 49.
Answer. 49.
Comments
Leave a comment