HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
With the for loop, you can also create ranges of values with .."
With the for
loop, you can also create
ranges of values with "..
":
Print the whole alphabet:
for (chars in 'a'..'x') {
println(chars)
}
You can also create ranges of numbers:
for (nums in 5..15) {
println(nums)
}
Note: The first and last value is included in the range.
You can also use the in
operator to check if a value exists in
a range:
val nums = arrayOf(2, 4, 6, 8)
if (2 in nums) {
println("It exists!")
} else {
println("It does not exist.")
}
val cars = arrayOf("Volvo", "BMW", "Ford", "Mazda")
if ("Volvo" in cars) {
println("It exists!")
} else {
println("It does not exist.")
}
You can also use the break
and continue
keywords in a range/for
loop:
Stop the loop when nums
is equal to 10
:
for (nums in 5..15) {
if (nums == 10) {
break
}
println(nums)
}
Skip the value of 10 in the loop, and continue with the next iteration:
for (nums in 5..15) {
if (nums == 10) {
continue
}
println(nums)
}