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
fa Persian Download
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
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: WEBVTT 1 00:00:00.000 --> 00:00:04.000 Alright now let's 2 00:00:04.000 --> 00:00:08.000 take a look at the third kind of loop we have in JavaScript. 3 00:00:08.000 --> 00:00:12.000 That is a do-while loop. Do-while loops 4 00:00:12.000 --> 00:00:16.000 are very similar to y loops, but they're slightly different. It's 5 00:00:16.000 --> 00:00:20.000 easier to show you in code. So I'm going to rewrite this logic 6 00:00:20.000 --> 00:00:24.000 using a do-while loop. Just like the y loops, we have to declare 7 00:00:24.000 --> 00:00:28.000 our loop variable externally, so we declare i and 8 00:00:28.000 --> 00:00:32.000 initialize it to 0. Okay, now if we save the changes, 9 00:00:32.000 --> 00:00:36.000 we're going to get an error identifier has already been declared. 10 00:00:36.000 --> 00:00:40.000 Because I have declared i here, so I can not redeclare 11 00:00:40.000 --> 00:00:44.000 it here. This is different than the i that we have in the for loop, 12 00:00:44.000 --> 00:00:48.000 again, this is all about scoping, and I'm going to talk about that later in the course. 13 00:00:48.000 --> 00:00:52.000 So, to make this work I'm going to temporarily 14 00:00:52.000 --> 00:00:56.000 comment out these few lines, and rewrite this 15 00:00:56.000 --> 00:01:00.000 logic using a do while loop. So we add the do statement 16 00:01:00.000 --> 00:01:04.000 do statement here, then a code block, in this block we should 17 00:01:04.000 --> 00:01:08.000 have our statements. So I'm going to borrow them 18 00:01:08.000 --> 00:01:12.000 from our while loop, copy these, paste them here, 19 00:01:12.000 --> 00:01:16.000 and then finally at the end 20 00:01:16.000 --> 00:01:20.000 of this block we add the while statement along with 21 00:01:20.000 --> 00:01:24.000 our condition. That is i less than or equal to 5, 22 00:01:24.000 --> 00:01:28.000 followed by a semi colon. Now you might be wondering 23 00:01:28.000 --> 00:01:32.000 what is the difference between a while loop, and a do-while loop, 24 00:01:32.000 --> 00:01:36.000 do-while loops are always executed at least once. 25 00:01:36.000 --> 00:01:40.000 Even if this condition evaluates to false. Let me show you 26 00:01:40.000 --> 00:01:44.000 what I mean. So I'm going to temporarily comment out these few 27 00:01:44.000 --> 00:01:48.000 lines. And bring back our while loop. 28 00:01:48.000 --> 00:01:52.000 Also, we don't need this for block for now, so let's comment it out, 29 00:01:52.000 --> 00:01:56.000 now if you save the changes, we get 1, 3, 5 on 30 00:01:56.000 --> 00:02:00.000 the console. However, if I change i 31 00:02:00.000 --> 00:02:04.000 to 9, we are not going to see anything, because the first time 32 00:02:04.000 --> 00:02:08.000 we try to execute this while loop, this condition evaluates 33 00:02:08.000 --> 00:02:12.000 to false. So these statements are never executed. 34 00:02:12.000 --> 00:02:16.000 So save the changes, look, there's nothing in the console. So in 35 00:02:16.000 --> 00:02:20.000 while loops, this condition is evaluated ahead of time. 36 00:02:20.000 --> 00:02:24.000 At the beginning of every iteration. In contrast 37 00:02:24.000 --> 00:02:28.000 in do-while loops, 38 00:02:28.000 --> 00:02:32.000 this condition is evaluated at the end. And 39 00:02:32.000 --> 00:02:36.000 that means these statements are always executed 40 00:02:36.000 --> 00:02:40.000 at least once. Even if the condition is false. 41 00:02:40.000 --> 00:02:44.000 So let's try this, I'm going to comment out this while loop, 42 00:02:44.000 --> 00:02:48.000 and change i to 9, just like before. 43 00:02:48.000 --> 00:02:52.000 Save the changes, we get 9 on the console, 44 00:02:52.000 --> 00:02:56.000 why? Because in our do-while loop here, 45 00:02:56.000 --> 00:03:00.000 on line 15, we check to see if this is an odd-number it is, 46 00:03:00.000 --> 00:03:04.000 and display it on the console. Next, we increment i by 1, so i, 47 00:03:04.000 --> 00:03:08.000 is 10. Then, the condition is evaluated, of course it's 48 00:03:08.000 --> 00:03:12.000 false. So our loop will terminate. Now, realistically 49 00:03:12.000 --> 00:03:16.000 we're not going to use this do-while a lot in programming, 50 00:03:16.000 --> 00:03:20.000 there are situations you may want to use this, but in practical terms, 51 00:03:20.000 --> 00:03:24.000 most of the time you will be using a for or while loop. Just 52 00:03:24.000 --> 00:03:28.000 be aware of the difference between a while loop and a do while loop. 4557

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