0

Iteration question

fun f(x: String): Int { var z = 0 for(a in x) { z++ } return z } fun main(args: Array<String>) { println(f("hello")) } Answer ==> 5 I got the answer of the about statement right but would need a step by step explanation as to how (a ) plays a part here. I know (x) to be the param of the function (f) but couldn't get (a)

3rd Jul 2022, 3:18 PM
Habibu Mamudu
Habibu Mamudu - avatar
1 ответ
+ 1
Habibu Mamudu 🇬🇭 'a' is a each value of string 'x' if you print that, each character of string would be print.
3rd Jul 2022, 3:21 PM
A͢J
A͢J - avatar