Looping - Kotlin

Watch this here


  Output for all the following loop code.

                
    08-26 21:31:48.491 20988-20988/? I/System.out: 0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
 
                

for :

  "for" loop is used for looping list of item using index. Also we can use for loop for

                
     for (i in 0..10){
            println(i)
        }
 
                

foreach

  "for" loop is used for looping list of item using index. Also we can use for loop for

                
        (0..10).forEach{
            println(it)
        }
 
                

while :

  "for" loop is used for looping list of item using index. Also we can use for loop for

                
        var i=0
        while (i <= 10){
            print(i)
            i++
        }
 
                

do..while :

  "for" loop is used for looping list of item using index. Also we can use for loop for

                
        i=0
        do {
            print(i)
            i++
        }while (i <= 10)
 
                

12800 Subscribers