All language subtitles for 5- Do...while

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

Alright now let's

take a look at the third kind of loop we have in JavaScript.

That is a do-while loop. Do-while loops

are very similar to y loops, but they're slightly different. It's

easier to show you in code. So I'm going to rewrite this logic

using a do-while loop. Just like the y loops, we have to declare

our loop variable externally, so we declare i and

initialize it to 0. Okay, now if we save the changes,

we're going to get an error identifier has already been declared.

Because I have declared i here, so I can not redeclare

it here. This is different than the i that we have in the for loop,

again, this is all about scoping, and I'm going to talk about that later in the course.

So, to make this work I'm going to temporarily

comment out these few lines, and rewrite this

logic using a do while loop. So we add the do statement

do statement here, then a code block, in this block we should

have our statements. So I'm going to borrow them

from our while loop, copy these, paste them here,

and then finally at the end

of this block we add the while statement along with

our condition. That is i less than or equal to 5,

followed by a semi colon. Now you might be wondering

what is the difference between a while loop, and a do-while loop,

do-while loops are always executed at least once.

Even if this condition evaluates to false. Let me show you

what I mean. So I'm going to temporarily comment out these few

lines. And bring back our while loop.

Also, we don't need this for block for now, so let's comment it out,

now if you save the changes, we get 1, 3, 5 on

the console. However, if I change i

to 9, we are not going to see anything, because the first time

we try to execute this while loop, this condition evaluates

to false. So these statements are never executed.

So save the changes, look, there's nothing in the console. So in

while loops, this condition is evaluated ahead of time.

At the beginning of every iteration. In contrast

in do-while loops,

this condition is evaluated at the end. And

that means these statements are always executed

at least once. Even if the condition is false.

So let's try this, I'm going to comment out this while loop,

and change i to 9, just like before.

Save the changes, we get 9 on the console,

why? Because in our do-while loop here,

on line 15, we check to see if this is an odd-number it is,

and display it on the console. Next, we increment i by 1, so i,

is 10. Then, the condition is evaluated, of course it's

false. So our loop will terminate. Now, realistically

we're not going to use this do-while a lot in programming,

there are situations you may want to use this, but in practical terms,

most of the time you will be using a for or while loop. Just

be aware of the difference between a while loop and a do while loop.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.