วันพฤหัสบดีที่ 25 มกราคม พ.ศ. 2561

Kotlin



The following is the link to 'Essential English Grammar for Reading Comprehension' topic

https://readinterestinglinks.blogspot.com/2015/11/the-following-are-topics-of-english.html


The following is the link to 'How to Write Your First Program' topic

http://readinterestinglinks.blogspot.com/2018/01/how-to-write-your-first-program.html


The following is link to 'Programming for Kids' topic

http://readinterestinglinks.blogspot.com/2016/07/programming-for-kids.html


The following is link to 'Android' topic

http://readinterestinglinks.blogspot.com/2016/04/android.html


The following is the link to 'Java' topic

http://readinterestinglinks.blogspot.com/2015/12/java.html


The following is the link to 'Python' topic

https://readinterestinglinks.blogspot.com/2019/02/python.html


The following is link to 'Rust' topic

https://readinterestinglinks.blogspot.com/2019/04/rust.html


The following is link to 'Dart and Flutter' topic

https://readinterestinglinks.blogspot.com/2019/04/dart-and-flutter.html


The following is link to 'A-Frame' topic

https://readinterestinglinks.blogspot.com/2019/04/a-frame.html


The following is link to ' Arduino and Raspberry Pi ' topic

http://readinterestinglinks.blogspot.com/2017/04/arduino-and-raspberry-pi.html


The following is link to 'Electronics Engineering' topic
http://readinterestinglinks.blogspot.com/2017/05/electronics-engineering.html


The following is link to 'Brain' topic

http://readinterestinglinks.blogspot.com/2016/03/brain-wavecomaxenoglossyreincarnation.html


=============================

https://riptutorial.com/kotlin

https://riptutorial.com/ebook/kotlin

https://www.tutorialspoint.com/kotlin/index.htm

https://www.tutorialspoint.com/kotlin/kotlin_quick_guide.htm

https://www.raywenderlich.com/1144981-kotlin-for-android-an-introduction





============================================

The links below are created before Aug, 2019



The following is link to 'Essential English Grammar for Reading Comprehension' topic

http://readinterestinglinks.blogspot.com/2015/11/the-following-are-topics-of-english.html


The following is link to 'English Listening ' topic

http://readinterestinglinks.blogspot.com/2015/12/english-listening.html




The following is link to 'Unity' topic

http://readinterestinglinks.blogspot.com/2016/12/unity-engine.html




The following is link to 'Java' topic

http://readinterestinglinks.blogspot.com/2015/12/java.html


The following is link to 'Haxe' topic

http://readinterestinglinks.blogspot.com/2015/12/haxe.html


The following is link to 'Android' topic

http://readinterestinglinks.blogspot.com/2016/04/android.html

The following is link to 'C++' topic

http://readinterestinglinks.blogspot.com/2015/12/c.html



========================




















https://kotlinlang.org/docs/reference




https://kotlinlang.org/docs/tutorials/edu-tools-learner.html




https://kotlinlang.org/docs/tutorials/koans.html




https://try.kotlinlang.org/#/Kotlin%20Koans/Introduction/Hello,%20world!/Task.kt


---------------------------------

https://www.callicoder.com/categories/kotlin




https://www.callicoder.com/kotlin-introduction-hello-world




https://www.callicoder.com/kotlin-functions


------------------------------------------

https://tutorialwing.com/tutorials/kotlin/





https://tutorialwing.com/kotlin-basic-data-types/





https://tutorialwing.com/kotlin-constants-and-literals/


----------------------------------

https://www.tutorialspoint.com/kotlin/index.htm




https://www.tutorialspoint.com/kotlin/kotlin_architecture.htm


------------------------------------------------ TornadoFX Plugin
The following is link to 'Java' topic

http://readinterestinglinks.blogspot.com/2015/12/java.html



https://docs.oracle.com/javafx/2/get_started/fxml_tutorial.htm




https://www.callicoder.com/categories/javafx


https://www.callicoder.com/javafx-fxml-form-gui-tutorial/




https://edvin.gitbooks.io/tornadofx-guide/content/part1/1.%20Why%20TornadoFX.html




https://edvin.gitbooks.io/tornadofx-guide/content/part1/2.%20Setting%20Up.html




https://edvin.gitbooks.io/tornadofx-guide/content/part1/12.%20TornadoFX%20IDEA%20Plugin.html




https://edvin.gitbooks.io/tornadofx-guide/content/part1/10.%20FXML.html









------------------------------------- Kotlin and Android

https://www.raywenderlich.com/category/android




https://www.raywenderlich.com/174395/kotlin-for-android-an-introduction-2




https://tutorialwing.com/creating-first-project-in-android-studio-using-kotlin-programming-language/


----------------------------------------- Kotlin and Libgdx

https://github.com/libgdx/libgdx/wiki/Using-libGDX-with-Kotlin




https://github.com/libgdx/libgdx/wiki/Project-Setup-Gradle




https://kotlinlang.org/docs/reference/using-gradle.html




https://github.com/haxpor/blockbunny




https://github.com/reime005/splintersweets


How to Write Your First Program


Download the PDF file of this topic

Another link




Last Edited : February 2014

How to write your first program

There are at least three topics that you need to know before you write you first program:
1)If statement
2)The scope of variables
3)Loop
Note that even though I use Java in this tutorial,you might be able to apply this tutorial to other programming languages because there are similarities between most programming languages,and I do not explain OOP(Object Oriented Programming) in this tutorial.



Print the value of variables and comment lines of code

Actually,you should know how to print the value of variables and how to comment your lines of code before those three topics above because the easiest way that can help you find the reason why your program does not work as you expected is to print the value of variables.

As for comment,if you know how to comment,you can use comments to explain other programmers how your code works
or use comments to remind yourself how your code works in case you forget it after a few weeks pass.

Your comments will not affect what your program will do because compiler will ignore the lines of code that you comment or any texts that are your comments.

You can use single-line comments or multi-line comments to add comments in your code.
Single-line comments start with '//' ,and the compiler ignore any texts after '//' until the end of the line
Multi-line comments start with '/*' and end with '*/'  ,and the compiler ignore any texts between '/*' and  '*/'

The following program shows you how to print the value of variables before using single-line comments.

 

==========




image file : PrintValueExample1NoCommentProgram.png X50
==========



The following result is produced by the above program.

 

==========


image file : PrintValueExample1NoCommentResult.png X20
==========

The following program shows you how to print the value of variables after using single-line comments.

 

==========


image file : PrintValueExample1HasCommentProgram.png X80
==========

The following result is produced by the above program.

 

==========


image file : PrintValueExample1HasCommentResult.png X20
==========

As you can see,the texts that are used to explain how the program works do not affect the result of the program,so the program still produces the same result.

The following program shows you how to print the value of variables before using both single-line comments and multi-line comments.

 

==========


image file : PrintValueExample2NoCommentProgram.png X50
==========

The following result is produced by the above program.

 

==========


image file : PrintValueExample2NoCommentResult.png X20
==========

The following program shows you how to print the value of variables after using both single-line comments and multi-line comments.

 
==========


image file : PrintValueExample2HasCommentProgram.png X80
==========


The following result is produced by the above program.

 
==========


image file : PrintValueExample2HasCommentResult.png X20
==========

As you can see,the lines of code that are commented do not affect the result of the program anymore.



If statement


if(condition)
{
statements
}


The statements in the block 'if' (if block of code) will be executed if the condition is true

If...else statement


if(condition)
{
statements
}
else
{
statements
}



The statements in the block 'if' (if block of code) will be executed if the condition is true,and
the statements in the block 'else' (else block of code) will be executed if the condition is false

The following program shows you how if statement and if...else statement work.

 

==========


image file : IfExampleProgram.png X80
==========


The following result is produced by the above program.


 


==========


image file : IfExampleResult.png X50
==========

To summarize,the statements in the block 'if' will be executed if the condition is true.





The scope of variables

A block starts with  '{' (opening curly brace) and ends with  '}' (closing curly brace).
You need to declare a variable in a block before you can use the variable.
In other words,after you declared a variable in a block,you can use the variable as long as the statement that you use the variable is after the the statement that you declared the variable and is before the closing curly brace of the block that the variable was declared in.

Note that there are other kinds of variables such as the property of an object in OOP(Object Oriented Programming),but I do not mention it in this topic.

The following program shows you the value of the variables varDeclaredInTheBlockMain and varDeclaredInTheBlockIf.

 


==========



image file : LocalVarExamplePrintValueBlockIfProgram.png X80

==========


The following result is produced by the above program.

 



==========




image file : LocalVarExamplePrintValueBlockIfResult.png X50

==========


The following program shows you the value of the variables varDeclaredInTheBlockMain and varDeclaredInTheBlockElse after the old value of varDeclaredInTheBlockMain is commented and the new value is assigned to the variable varDeclaredInTheBlockMain.


 



==========




image file : LocalVarExamplePrintValueBlockElseProgram.png X80

==========


The following result is produced by the above program.


 


==========




image file : LocalVarExamplePrintValueBlockElseResult.png X50

==========



The following sketch shows you the scope of the variable varDeclaredInTheBlockMain.

 


==========




image file : ScopeVarTheBlockMain.png X50

==========



The following sketch shows you the scope of the variable varDeclaredInTheBlockIf.

 


==========




image file : ScopeVarTheBlockIf.png X50

==========



The following sketch shows you the scope of the variable varDeclaredInTheBlockElse.

 


==========




image file : ScopeVarTheBlockElse.png X50

==========



To summarize,you need to declare a variable before you can use it. The statement that you use the variable need to be between the statement that you declared the variable and the closing curly brace of the block that the variable was declared in




Loop

You can use loop when you want your program to do the same thing or execute the same statements many times.

The for loop


for(initialization;condition;increment)
{
statements
}


The statements in the block of the loop 'for' will be executed many times as long as the condition part is true.
People tend to use the for loop when they know how many times the statements in the block will be repeated.

The initialization part is executed only one time and usually used to initialize the loop control variable that will be used in the condition part and increment part.
The condition part is checked. If the condition part is true,the statements in the block will be executed.
After the statements in the block is executed,the increment part will update the loop control variable,and then the condition part will be checked again for the next iteration of the loop.

These three steps (execute statements in the block,update the increment part ,and check the condition part for the next iteration of the loop) will be repeated in order until the condition part is changed to be false.

Note that the increment part will be updated before the condition part is checked for the next iteration of the loop,and the increment part is usually used to change the condition part to be false,otherwise the  loop will be infinite loop.

The following program shows you how a for loop works.

 



==========




image file : LoopExampleProgram.png X40

==========


The following result is produced by the above program.

 



==========




image file : LoopExampleResult.png X15

==========


To summarize,the statements in the block of the loop 'for' will be executed many times as long as the condition part is true,and the increment part will be updated before the condition part is checked for the next iteration.




The continue statement

The continue statement causes the program to ignore the statements that are after the continue statement and goes to the next iteration of the loop if the condition of the loop is still true.

The following program shows you how a continue statement works.

 


==========




image file : ContinueLoopExampleProgram.png X40

==========



The following result is produced by the above program.

 


==========




image file : ContinueLoopExampleResult.png X10

==========



As you can see,the program do not print the value of the variable ' i ' when the value of the variable ' i ' is equal to 4.

The following sketch gives you a rough idea of how the continue statement in the loop works when the condition of the if statement is true,but you should not forget that the increment part will be updated before the condition part will be checked for the next iteration of the loop.

 



==========




image file : ContinueLoopExampleProgramRoughIdea.png X45

==========


To summarize,the continue statement causes the program to go to the next iteration of the loop if the condition of the loop is still true.




The break statement

The break statement causes the program to go out of the loop that the the break statement is in and go to the statement that is after the block of the loop that the the break statement is in.

The following program shows you how a break statement works.

 



==========




image file : BreakLoopExampleProgram.png X50

==========


The following result is produced by the above program.

 


==========




image file : BreakLoopExampleResult.png X35

==========



As you can see,the program stop printing the value of the variable ' i ' when the value of the variable ' i ' is equal to 5,so the program does not print the line 'i = 5' and the line 'i = 6' anymore.

The following sketch gives you a rough idea of how the break statement in the loop works when the condition of the if statement is true.

 


==========




image file : BreakLoopExampleProgramRoughIdea.png X45

==========



To summarize,the break statement causes the program to go out of the loop that the break statement is in.




Nested loop

A loop can be inside another loop. What a nested loop does is that the inner loop will finish the last iteration of the inner loop before the outer loop starts the next iteration of the outer loop. In other words,the inner loop spins faster than the outer loop.

The following program shows you how a nested loop works.

 



==========




image file : NestedLoopExampleProgram.png X65

==========


The following result is produced by the above program.

 



==========




image file : NestedLoopExampleResult.png X50

==========


As you can see,the inner loop will print ' j = 1 ' again when the value of the variable ' i ' is equal to 8.

The following image shows you the same result,but there are four lines in a red border.
These four lines are ' i = 7 , j = 4 ', 'This line is after the inner loop and in the outer loop'
, 'This line is before the inner loop and in the outer loop' ,and ' i = 8 , j = 1 '.
These four lines help you understand how the nested loop works.

 



==========




image file : NestedLoopExampleResultInBorder.png X50

==========


The following sketch gives you a rough idea of how inner loop and outer loop work.

 

To summarize,the inner loop spins faster than the outer loop.




==========




image file : NestedLoopExampleProgramRoughIdea.png X50

==========




Nested loop and the break statement

If there is a break statement in the inner loop,after the break statement causes the program to go out of the inner loop,the program is still in the outer loop.

The following program shows you how a break statement in an inner loop works.

 


==========




image file : BreakNestedLoopExampleProgram.png X65

==========



The following result is produced by the above program.

 


==========




image file : BreakNestedLoopExampleResult.png X45

==========



As you can see,the program does not print the the line ' i = 7 ,  j = 3 ' and the the line ' i = 7 ,  j = 4 ' anymore when the value of the variable ' j ' is equal to 3,but the program is still in the outer loop,so it prints the line 'This line is after the inner loop and in the outer loop' ,and then it goes the next iteration of the outer loop because the condition part of the outer loop is still true when the variable ' i ' is equal to 8,so it prints the line 'This line is before the inner loop and in the outer loop' ,and then prints the line ' i = 8 ,  j = 1 ',and then it prints the other lines as you can see.

The following image shows you the same result,but there are four lines in a red border.
These four lines are ' i = 7 , j = 2 ', 'This line is after the inner loop and in the outer loop'
, 'This line is before the inner loop and in the outer loop' ,and ' i = 8 , j = 1 '.
These four lines help you understand how the break statement in the inner loop works.

 


==========




image file : BreakNestedLoopExampleResultInBorder.png X45

==========



The following sketch gives you a rough idea of how the break statement in the inner loop works when the condition of the if statement is true.

 


==========




image file : BreakNestedLoopExampleProgramRoughIdea.png X65

==========



To summarize,after the break statement causes the program to go out of the inner loop,the program is still in the outer loop.



Note that if you have never created your first project or 'Hello World' project yet,the following webpage can help you.
http://wiki.jetbrains.net/intellij/Creating_and_running_your_first_Java_application