- Overview
- Transcript
2.3 Comments
In this lesson, you'll learn the syntax related to comments. I'll show you multi-line and single-line comments and the coding conventions related to them.
1.Introduction3 lessons, 07:48
1.1Introduction01:16
1.2Kotlin Overview04:06
1.3Installing IntelliJ IDEA02:26
2.Get Started With Kotlin7 lessons, 41:00
2.1Your First Program09:11
2.2Using the REPL03:03
2.3Comments02:52
2.4Variables and Data Types07:20
2.5Classes and Functions06:29
2.6Imports and Constructors04:31
2.7Inheritance07:34
3.Features and Syntax7 lessons, 40:53
3.1Goodbye Null Pointer Exception07:58
3.2String Templates and Interpolation07:44
3.3Ranges and the Double Dot Operator03:03
3.4`if` and `when` as Expressions07:08
3.5Loops and Iterators: the `for` Loop03:28
3.6Loops and Iterators: the `while` and `do`...`while` Loops04:57
3.7Loop Control Statements With Labelled `for` Loops06:35
4.Some Advanced Features2 lessons, 13:26
4.1Lambdas and Higher-Order Functions09:11
4.2Interoperability04:15
5.Conclusion1 lesson, 01:17
5.1Conclusion01:17
2.3 Comments
Hello, I'm Anna and in this lesson we will be learning about comments in Kotlin. So let's see what are comments, and how do we write comments in Kotlin. Comments are the line of code that the compiler simply ignores while executing the codes. Here I had said that main function Is the first function to be executed when our Kotlin app runs. So let us mention this in our comment. If you want to write the comment in a single line use the // followed by space. Space is usually important because of the coding standards. So let's write the command for this main function. Let's save it write is the first function to be executed when the app runs. What if you want to write multiple lines of code? You can write like this, but this is not the conventional way. If you want your function header to have multiple lines which usually is the syntax for it is /**/. Press enter and the star will be automatically printed for you. And then enter, enter, enter and you're get this for writing your comments. To write the multiple line of comment we have this syntax, /**/. If you want to write a single line comment you can mention it here. The compiler comes to execute printIn("Hello World"). But when it finds the comment, it simply ignores it. So no matter what, your comment will not affect the execution of the code at any cost. You can write the single line comment here. Let us run our code and see what happens. We only have hello world printed, but if you write a code after the comment thinking that it will be executed, you're wrong. The compiler will treat this entire statement which follows the forward slashes, it will be treated as comment. Let's see what happens here. You see, we get nothing in the output because this line is completely ignored by the compiler thinking that it is a comment. So, if you want your statement to be executed, write in a fresh line or write the comment after it. So this is all about comments. In the next video we will be learning about variables and data type in Kotlin. I'll also tell you about Val and Val keyword and what are the differences between the two. Until then, happy programming, keep smiling and have a good day.