Lecture 1- Kotlin Programming Language Introduction_١١٠٠١٨_065349
Lecture 1- Kotlin Programming Language Introduction_١١٠٠١٨_065349
Programming
Language
An Introduction
Kotlin Syntax
• The fun keyword is used to declare a function. A function is a block of code
designed to perform a particular task. In the example above, it declares the
main() function.
• The main() function is something you will see in every Kotlin program. This
function is used to execute code. Any code inside the main() function's curly
brackets {} will be executed.
• For example, the println() function is inside the main() function, meaning that
this will be executed. The println() function is used to output/print text, and in
our example it will output "Hello World".
Introduction to Kotlin
Programming Language
Kotlin Output
• The println() function is used to output values/print text.
• You can add as many println() functions as you want.
Note that it will add a new line for each function.
• You can also print numbers, and perform mathematical
calculations.
• There is also a print() function, which is similar to
println(). The only difference is that it does not insert a
new line at the end of the output:
Kotlin Output
Kotlin Output
Kotlin Output
Kotlin Comments
• Comments can be used to explain Kotlin code, and to make it
more readable.
• It can also be used to prevent execution when testing alternative
code.
• Single-line comments starts with two forward slashes (//): Any
text between // and the end of the line is ignored by Kotlin (will
not be executed).
• Multi-line comments start with /* and ends with */: Any text
between /* and */ will be ignored by Kotlin.
Kotlin Comments
Kotlin Comments
Kotlin Comments
Kotlin Variables
• Variables are containers for storing data values.
• To create a variable, use var or val, and assign a value to
it with the equal sign (=).
• Syntax:
var variableName = value
val variableName = value
Kotlin Variables
• The difference between var and val is that variables
declared with the var keyword can be changed/modified,
while val variables cannot.
• Variables in Kotlin do not need to be declared with a
specified type (like "String" for text or "Int" for numbers,
if you are familiar with those).
Kotlin Variables
• The difference between var and val is that variables
declared with the var keyword can be changed/modified,
while val variables cannot.
• Variables in Kotlin do not need to be declared with a
specified type (like "String" for text or "Int" for numbers,
if you are familiar with those).
Kotlin Variables
When you create a variable with the val keyword, the value
cannot be changed/reassigned. The following example will
generate an error:
Kotlin Variables
When using var, you can change the value whenever you
want:
Kotlin Variables