You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
4.2 KiB
87 lines
4.2 KiB
<!doctype html> |
|
<html> |
|
<head> |
|
<meta charset="utf-8"> |
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
|
<title>My Learning Website</title> |
|
<link href="/styles/styles.css" rel="stylesheet" type="text/css"> |
|
<link href="/android/styles/styles.css" rel="stylesheet" type="text/css"> |
|
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> |
|
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> |
|
<!--[if lt IE 9]> |
|
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> |
|
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> |
|
<![endif]--> |
|
</head> |
|
<body> |
|
|
|
<div class="banner"> |
|
<h1 class="courselink"><a href="https://www.linkedin.com/learning/kotlin-essential-training-2018">Kotlin Essential Training</a></h1> |
|
<h2 class="lecturer">LinkedIn Learning : David Gassner : March 2018</h2> |
|
<h2 class="episodetitle">Additional Notes</h2> |
|
</div> |
|
|
|
<article> |
|
<h2 class="sectiontitle">if Expressions</h2> |
|
<p>There are some useful videos on YouTube created by Peter Somerhoff and it is well worth subscribing to his channel. In particular, there are a couple of tutorial playlists of Lotlin tutorials.</p> |
|
<pre class="inset"> |
|
<a href="https://youtu.be/AcwzpPLV5HY">Kotlin Tutorial</a> - 22 videos. |
|
<a href="https://youtu.be/YpD3k22C-8Q">Kotlin for Android and Java Developers</a> - 12 videos.</pre> |
|
<p>These notes are from video 5 in the Kotlin for Android and Java Developers playlist.</p> |
|
<p>The Android Studio provides a facility that may be quite useful when developing code and that is the Kotlin REPL (REPL stands for Read-Eval-Print-Loop). This can be accessed via the Tools menu by selecting first Kotlin and then Kotlin REPL and this opens up a small integrated command line at the bottom of the screen. It should have a tab labelled something like Kotlin REPL (in module app) where app will be the name of your project and you may have to select it.</p> |
|
<p>Here, you can type in Kotlin code a line at a time and it is interpreted in much the same way as Python would be if using a command line interface or IDLE in interpreter mode.</p> |
|
<p>Another interesting point is really expanding on a point made in the section here entitled “Evaluate Conditions With If and Else” which mentions the fact that you can combine an assignment expression with an if statement. The video takes this a little further and notes that for any block of code in an if/if else/else block, the last statement returns the value for the assignment and this can be a simple expression such as a string or a variable name.</p> |
|
<pre class="inset"> |
|
val i=17 |
|
val x=if (i < 15) { |
|
println("i is pretty small") |
|
"small" |
|
} else if (i >=15 && i <= 25) { |
|
println("it's okay") |
|
"medium" |
|
} else { |
|
println("it's pretty large") |
|
"large" |
|
}</pre> |
|
<p>The result of executing this code is that the string “it’s okay” is printed. We don’t print the value of x here but we can print this after the code has executed and we can see that the value “medium” has been assigned to it.</p> |
|
|
|
</article> |
|
|
|
<div class="btngroup"> |
|
<button class="button" onclick="window.location.href='setting.html';"> |
|
Chapter 1 |
|
</button> |
|
<button class="button" onclick="window.location.href='getstarted.html'"> |
|
Chapter 2 |
|
</button> |
|
<button class="button" onclick="window.location.href='variables.html'"> |
|
Chapter 3 |
|
</button> |
|
<button class="button" onclick="window.location.href='flow.html'"> |
|
Chapter 4 |
|
</button> |
|
<button class="button" onclick="window.location.href='classes.html'"> |
|
Chapter 5 |
|
</button> |
|
<button class="button" onclick="window.location.href='data.html'"> |
|
Chapter 6 |
|
</button> |
|
<button class="button" onclick="window.location.href='inheritance.html'"> |
|
Chapter 7 |
|
</button> |
|
<button class="button" onclick="window.location.href='appendixb.html'"> |
|
Appendix B |
|
</button> |
|
<button class="button" onclick="window.location.href='code.html'"> |
|
Code Samples |
|
</button> |
|
<button class="button" onclick="window.location.href='/android/android.html'"> |
|
Android Page |
|
</button> |
|
<button class="button" onclick="window.location.href='/index.html'"> |
|
Home |
|
</button> |
|
</div> |
|
</body> |
|
</html>
|
|
|