Control flow Part 02|FOR LOOP|WHILE LOOP|DO..WHILE LOOP|BREAK AND CONTINUE
Loops
Loop is a control structure that repeats the same set of instructions until a termination condition is met.
In Kotlin, loops can iterate through anything that provides iterator.
Iterator is an interface that has two methods: hasNext and next.
It knows how to iterate over a collection, range, string, or any entity that can be represented as a sequence of elements.
Kotlin provides three kinds of loops: for, while, and do... while.
All of them work the same as in other programming languages, so we will discuss them briefly.
THE FOR LOOP
The classic Java for loop, where we need to define the iterator explicitly, is not present in Kotlin.
If a collection is a generic collection, then item will be smart casted to type corresponding to a generic collection type.
THE WHILE LOOP
The while loop repeats a block, while its conditional expression returns true
The main difference between both while and do... while loops is when a conditional expression is evaluated.
A while loop is checking the condition before code execution and if it is not true then the code won't be executed.
On the other hand, a do... while loop first executes the body of the loop, and then evaluates the conditional expression, so the body will always execute at least once.
If this expression is true, the loop will repeat. Otherwise, the loop terminates.
BREAK AND CONTINUE
All loops in Kotlin support classic break and continue statements.
The continue statement proceeds to the next iteration of that loop while break stops the execution of the most inner enclosing loop
Thanks for watching this video,
Don't forget to LIKE, SHARE, SUBSCRIBE and hit the bell icon to get newly upload video.
~-~~-~~~-~~-~
Please watch: "String manipulation in Python #codingtutorial #python #programminglanguage #coding"
• Make Python Work For You! Master Stri...
~-~~-~~~-~~-~
On this page of the site you can watch the video online kotlin - Control flow Part 02|FOR LOOP|WHILE LOOP|DO..WHILE LOOP|BREAK AND CONTINUE with a duration of hours minute second in good quality, which was uploaded by the user EDUDREAMS 30 May 2020, share the link with friends and acquaintances, this video has already been watched 40 times on youtube and it was liked by 2 viewers. Enjoy your viewing!