Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
With all the
loops you have learned about in this section, there are two keywords,
break and continue that can change how the loop behaves. In this demo I'm going to
use a while loop. But what you're going to learn applies to all loops
we have learned in this section. So let's start by declaring a variable
called i and initialize it to 0. Now we put this
in a while loop, as long as while is less than or equal to
10, we're going to display i on the console
and then increment it. Save the changes, so
this gives us numbers 0-10. Now sometimes you want to jump
out of a loop for some reason that may happen at run time.
For example, here we can have an if condition
an if statement, with a condition like this.
If i equals 5, we want to jump out of this loop.
That's where we use the break keyword. Now when we save
the changes, see what happens we get the numbers 0
to 4. So at the end of the 5th iteration here we
increment i, now i is 5, so we break out of the loop.
Now let me comment this out and look at the continue keyword.
So I'm going to write another if statement, I want to see
if i is an even number or not. So i,
module is 2, equals 0. If that's the case,
I want to increment i and then continue.
Let's see what happens when we run this code. Save the changes,
we only get the odd numbers, why is that? Alright
let's take a look at an example. So when i becomes 2,
it's an even number, at this point increment i,
i will be 3. Now when the JavaScript engine sees the
continue keyword. It will jump to the beginning of the loop.
And continues it's execution in the next iteration.
At this point i is 3, so this if statement is not executed,
that's why we see i on the console. Now,
in my personal experience, continue is not something you will use that often,
it's one of those old legacy things in JavaScript, I'm only explaining
it here in case you see it in projects you're working on. It's not some
thing that I recommend you to use, it's an ugly way of writing code.
So just to recap with the correct keyword, you jump out of a
loop, and with the continue keyword, we jump to the next iteration.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.