0

What is wrong?

fun main(args: Array<String>) { val n = arrayof(4,6,7,0,8) for(n in 8) // if for(8 in n) this is also show error {println("yes")} }

6th Aug 2021, 2:47 PM
Aman Verma
2 Réponses
+ 2
You should write : for (i in n) { if (i == 8) { println("Yes") } } Explanation: First, i = 4. Then check it with IF statement. But it isnt equal to 8. So iteration will be continued. Second, i = 6. It also continued. .... Last, i = 8. Then check it and the result is TRUE. Because it is true, it will be printed.
6th Aug 2021, 4:11 PM
Rijal Muhyidin
Rijal Muhyidin - avatar
0
Thanks
6th Aug 2021, 5:01 PM
Aman Verma