kotlin - Control flow Part 02|FOR LOOP|WHILE LOOP|DO..WHILE LOOP|BREAK AND CONTINUE

Publicado el: 30 mayo 2020
en el canal de: EDUDREAMS
40
2

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...  
~-~~-~~~-~~-~


En esta página del sitio puede ver el video en línea kotlin - Control flow Part 02|FOR LOOP|WHILE LOOP|DO..WHILE LOOP|BREAK AND CONTINUE de Duración hora minuto segunda en buena calidad , que subió el usuario EDUDREAMS 30 mayo 2020, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 40 veces y le gustó 2 a los espectadores. Disfruta viendo!