Day31 of #100DaysOfCode
2 min readMar 9, 2022
Hii folks 🙌
After completing the series of JavaScript30, from today I’m going to start learning Android Basics in Kotlin
Unit 1: Kotlin basics
Pathway 1: Introduction to Kotlin
Source: https://developer.android.com/courses/android-basics-kotlin/course
Learnings:
- All Kotlin programs need to have a
main()
function:fun main() {}
- We use the
println()
function to print a line of text. - We place the text between double quotes to print. For example
"Hello"
. - Errors are marked red in the program. There is an error message in the output pane to help us figure out where the error is and what might be causing it.
fun main() {
println("Happy Birthday!")
}
Create a birthday message in Kotlin
- We create a variable using the
val
keyword and a name. Once set, this value cannot be changed. Examples of values are text and numbers.
val age = 5
- Use
${}
to surround variables and calculations in the text of print statements. For example:${age}
whereage
is a variable. AString
is text surrounded by quotes, such as"Hello"
.
println("You are already ${age} days old, ${name}!")
- An
Int
is a whole positive or negative number, such as 0, 23, or -1342. - We can pass one or more arguments into a function for the function to use it, For example:
fun printCakeBottom(age: Int, layers: Int) {}
- We use a
repeat() {}
statement to repeat a set of instructions several times. For example:
repeat (23) { print("%") }
repeat (layers) { print("$$$$$$$") }
- A loop is an instruction to repeat instructions multiple times. A
repeat()
statement is an example of a loop. - We can nest loops, that is, put loops within loops. For example, we can create a
repeat()
statement within arepeat()
statement to print a symbol a number of times for a number of rows. For example:
fun printCakeBottom(age: Int, layers: Int) {
repeat(layers) {
repeat(age + 2) {
print("@")
}
println()
}
}
And then attempted the quiz, and this is what I got! 🎊
That is all for Day31 ✅
Thanks for reading, See you tomorrow!