For loop in Kotlin to print value from 10 to 1?


Warning: Trying to access array offset on false in /home3/indiakep/public_html/wp-content/plugins/dw-question-answer/inc/Template.php on line 8
All QuestionsCategory: KotlinFor loop in Kotlin to print value from 10 to 1?
chetan shidling asked 5 years ago

I need short information.

1 Answers
chetan shidling answered 5 years ago

Here is the code to print values from 10 to 1 in Kotlin.
 
fun main(args : Array<String>){
var nums = 10 downTo 1

for(a in nums)
{
println(a)
}
}
 
Output:
 
10
9
8
7
6
5
4
3
2
1