2.2 Using the REPL
In this lesson, you'll learn how to use the interactive shell in IntelliJ IDEA. This tool makes it easy to try out code and simplifies testing while building applications.
1.Introduction3 lessons, 07:48
2.Get Started With Kotlin7 lessons, 41:00
3.Features and Syntax7 lessons, 40:53
4.Some Advanced Features2 lessons, 13:26
5.Conclusion1 lesson, 01:17
2.2 Using the REPL
Hey there! In this lesson, we will be learning about REPL, which stands for read-eval-print loop. Now let me show you what is REPL. We can say REPL is a console which we can use to test our codes in Kotlin. It is an interactive shell which we can use to run the code and see the results. So let's see how can we work with REPL. Click on the tools, select the Kotlin option and then Kotlin REPL. Here we have the window for REPL. Here it says to execute. And yes this is an important point. To execute the code, we need to press CTRL+Enter, and if you're using Mac OS, press Command+Enter. Let us write some codes in REPL, and see how it execute. Let's say 5+5 Command+Enter, we have 10. Let's say println("Welcome to Envato Tuts+"), CTRL + Enter. Welcome to Envato Tuts+, you see? How is it to execute the code and see in REPL? We can use this for testing purpose. Now, if we write 10/6, CRTL+Enter, we have one. How come is it one? Be sure to should have some decimal values right. But since 10 and 6 both are integers, we will have the output as an integer. To get the exact value for 10/6, which will be a floating type value, we need to write 10.0/6, and then CTRL+Enter, we have the exact result here. Now what if we want to write multiple lines of code? Let's see. In which var is the keyword, that we need when we want to define a variable. And here, the variable is str. And then, let's define the second variable on pressing enter p move to the next line. But if we press Ctrl+Enter, we have the code executed for us. Now let us print (str + str1), and then CTRL+Enter. And here we have Welcometo the world. So this is all about triple. If you want to write multiple lines of code, press enter. If you want to execute the code, press CTRL+Enter. Play around with REPL and have a good day. See you in the next lesson in which I'll be telling you how to write comments in Kotlin. Keep coding and keep smiling.