Then, we have displayed a message on the terminal. We have assigned the names of all the days to this array as its elements. After that, we have defined an array of the days of the week with the title “week” by using the “arrayOf” keyword. Then, within this document, we have defined the “main()” function with the “fun main()” statement. ![]() All the Kotlin scripts must have the “.kt” extension with their name. We have first created an empty document with the title “for.kt”. The example Kotlin script is shown in the image below: In this example, we will teach you the method of printing the elements of an array by using the “for” loop in Kotlin. To learn the usage of the Kotlin “for” loop in Ubuntu 20.04, you can take a look at the following five examples: Example # 1: Printing the Days of a Week utilizing the For Loop in Kotlin: This tutorial will learn to use the “for” loop in the Kotlin programming language in Ubuntu 20.04. ![]() This loop works exactly like the “foreach” loop in the C# programming language. All it needs is an iterator that helps this loop to iterate over the provided collection. The “for” loop in Kotlin is used for iterating over ranges, arrays, lists, etc., just like it is used in other programming languages.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |