0

I CANT UNDERSTAND THE EXECUTION OF THE PROGRAM.

calc <- function(a, b) { res <- 0 for(x in a:b) { res <- res + x } return(res) } print(calc(4, 7))

13th Oct 2022, 12:57 PM
REVATHI S
4 odpowiedzi
+ 1
What part exactly don't you understand? The for-loop iterates over the range of [a; b]. On each iteration the current number is added up to result.
13th Oct 2022, 1:01 PM
Lisa
Lisa - avatar
+ 1
You can re-read the lesson about loops as often as you like. 4+5+6+7 = 22
13th Oct 2022, 1:11 PM
Lisa
Lisa - avatar
+ 1
Thank you so much Lisa for Explanation..
13th Oct 2022, 1:14 PM
REVATHI S
0
The output is 22,i cant understand how the loop execute and how the output is 22.
13th Oct 2022, 1:10 PM
REVATHI S