All language subtitles for 004 Looping Arrays_en

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

Arrays and loops are like siblings previously defined an array that stores four kingdoms and you learn

how to access each element using its index.

Now, let's imagine the array had 20 elements, are you going to put 20 print statements and access

each index one by one?

Absolutely not.

That would be terrible.

Instead, we can use a loop that runs through every element in the array.

In this video, you're going to learn how to loop through an array of values.

The first thing you need to do is create a new class by yourself inside Section six.

Wow, that's a tongue twister inside your Section six folder, create a new file, need to raise an

Leapster Java and make sure the class has a main method.

So how can we loop through an array, a loop can run through every element in an array, but how does

that happen?

Let's have a look.

Inside arrays and loops make another kingdom's variable, it's going to be the exact same variable as

the last one, string kingdom's is equal to an array of string values.

W6.

Northumbria and East Anglia.

Yay for short.

The array has four elements, so you need a for loop that runs exactly four times, so I'm going to

say four enties is equal to zero.

The eye counter is going to start at zero because the index of a race first element starts at zero as

well.

And so it makes sense because the last index of an array race three.

The loop is going to keep running while the counter eye is less than the array's length for E-Plus plus.

And then I'm going to print the counter I during each run.

All right, this loop keeps running as long as it is less than four, I starts at zero and goes up until

three, basically designed this loop so that each counter value matches the index of an element so I

can use each counter value to index an element inside the kingdom array.

Some print the element at Inducts I.

And here will index the element from the kingdom's array.

And very nice, the for loop runs through every value in the array.

And here is a visual that I made for you.

I start at zero indexing the first element.

Increases up to one.

Indexing the second element.

And the loop keeps running until I equals three, which allows us to index the last elements.

Arrays of a length property that calculates the number of elements.

You can use the length to calculate the number of elements for kingdoms, right?

So here I'm going to print.

The number of elements is.

Kingdoms that length.

And indeed, the number of elements is four, because the array has four elements, so length equals

four.

And so inside the for loop, instead of writing is smaller than four, I'm going to write I is smaller

than kingdoms that length.

And nice, this works very well with that being said, you never need to count the elements yourself,

always use the length property to run through an array.

Now, here's something to consider when you look through an array.

Pay attention to the condition, because what if you replaced your condition with eyes smaller than

or equal to kingdoms that length?

In this case, the code crashes because the next four is out of range.

Because we start counting at zero, the last index number in an array is always going to be one smaller

than the array's length.

Into this loop runs as long as I is smaller than or equal to four.

In the fifth run, the counter is going to equal the array's length, for there is no element at index

four, so the code crashes.

So your loop should only run as long as it is smaller than the array length.

And now everything works, the loop keeps running right up until the last inducts and then the loop

stops.

In this lesson, we used a for loop to access each element in an array, your first for a loop ran through

the length of the kingdom's array and also because we start counting at zero, the last index number

is always one smaller than the array length.

So your condition for running through an array should always be smaller than the length of the array.

If I count up to an index that's equal to the length, your code is going to crash.

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