How to print list with for loop and index in Scala

1 Answer

0 votes
object O {
    def main(args: Array[String]): Unit = {
        val lst = List("scala", "c", "c++", "swift", "java", "php")

        for (i <- 0.until(lst.length)) {
            println(lst(i))
        }
    }
}
     
     
     
     
/*
run:
     
scala
c
c++
swift
java
php

*/

 



answered Oct 16, 2020 by avibootz

Related questions

2 answers 129 views
1 answer 120 views
1 answer 211 views
2 answers 228 views
1 answer 193 views
1 answer 131 views
1 answer 106 views
106 views asked Sep 3, 2024 by avibootz
...