English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In this program, you will learn to use while loops to print English letters in Kotlin. You will also learn to print only uppercase and lowercase letters.
fun main(args: Array<String>) { var c: Char c = 'A' while (c <= 'Z') { print("$c ") ++c } }
When the program is run, the output is:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Like Java, you can use a for loop to iterate from A to Z, because they are stored as ASCII characters in Kotlin.
Therefore, internally, you can loop to display65to90 to print English letters.
Here is the equivalent Java code:Java Program to Display English Letters
Make slight modifications, and you can display lowercase letters, as shown in the following example.
fun main(args: Array<String>) { var c: Char c = 'a' while (c <= 'z') { print("$c ") ++c } }
When the program is run, the output is:
a b c d e f g h i j k l m n o p q r s t u v w x y z
You just need to replace 'A' with 'a' and 'Z' with 'z' to display lowercase letters. In this example, in the inner loop97to122.