how to do a while loop kotlin

var i = 1
while (i < 5) { 	// while loop
	println(i)
	i++
}					

var i = 1
do { 				// do-while loop
	println(i)
	i++
} while (i < 5)		

4
2
Phoenix Logan 186120 points

                                    while ( isTrue() );

while ( isTrue() ) {
  println(&quot;while!&quot;)
}

do {
  println(&quot;do while!&quot;)
} while (isTrue())

4 (2 Votes)
0
4
6
Krish 100200 points

                                    for (item in collection) print(item)

4 (6 Votes)
0
3.8
5
Krish 100200 points

                                    //Here is how to do a while loop in kotlin!
//It is very similar to the syntax of javscript if youa have worked with the langauge!

// Program to print line 5 times

fun main() {

    var i = 1

    while (i &lt;= 5) {
        println(&quot;Line $i&quot;)
        ++i
    }
}

//this will print 5 times!
Line 1
Line 2
Line 3
Line 4
Line 5




//If your try copying and pasting the code put it in this function! Hopefully it will print!

fun main(args: Array&lt;String&gt;) {

println(&quot;Hello Bob&quot;)

}

3.8 (5 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to do a while loop kotlin kotlin while cycle do while kotlin example while loop vs for loop kotlin while kotlin android kotlin for until loop kotlin until loop kotlin loops until kotlin while example how to use while loop in kotlin kotlin loop until while loop in kotlinnn do while loop in kotlin kotlin do at the end of while loop kotlin while kotlin while keyword kotlin while assignment kotlin while true koltin while(true loops in kotlin iterate with while in kotlin kotlin take while while in kotlin while loop with else statement kotlin while loop for string values kotlin create a basic WHILE loop in KOTLIN kotlin while loop array kotlin for loop i++ is not possoble syntax when in kotlin while loops in kotlin case in kotlin kotlin repeat until while loop in kotlib do while in kotlin kotline while loop assignment and expression in a while loop statement kotlin assignment and expression in a while loop statement kotline kotlin for loop with condition for each statement i kotlin kotlin for x in int kotlin while loop example while statement in kotlin kotlin while statement wghile kotlin check condition on loop kotlin for loop in a while loop kotlin function and while loop kotlin kotlin do while for kotlin# kotlin while with declaration kotlin for while kotlin for kotlin kotlin for loop as expression kotlin do while loop for kotlin example kotlin for while lopps do while kotlin for cycle kotlin foor loop array kotlin while loop in kotlin kotlin constant while loop kotlin while loop while look kotlin do while not end of string kotlin while loop kotlin
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source