All language subtitles for 013 Debugging Nested Loops_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

Normally, the loops are very easy to control.

You simply need to trace the counter eye during each run, but nested loops rely on two counters I.

And so it can be hard to follow two counters at the same time.

So it helps to visualize the runtime using breakpoints.

In this lesson, you're going to learn to debug loops using breakpoints.

All right, first thing to do is apply breakpoints to the nested loop.

And so during the runtime, we're going to visualize and keep track of the counters I enjoy as the updates

to launch a new debugging session.

And as expected, everyone from the outer loop runs the inner loop 10 times, we can see that by looking

at the counters and this is going to keep happening till the outer loop breaks so we can go ahead and

stop the debugger.

All right, now, you were given the task of printing a half pyramid using Java, the pyramid just 10

rows, the first row starts with one star and the number of stars keeps increasing by one.

But if you run the current code.

This should be our output once again, the code you open doesn't behave like we want it to.

Something is wrong and using breakpoints, we can visualize the runtime and fix it step by step.

So I'm going to add one more breakpoint right here, then launch a new debugging session.

It seems that each pass from the outer loop runs the inner loop 10 times.

Every pass that follows princi row of 10 stars on the same line.

If you look back at the output, the most obvious step is to add a new line after every arrow.

So we can add a new line after the inner loop runs to completion right over here.

Stop the debugger.

We run the code.

And this pyramid should have 10 rows, so this is progress.

But how do we make sure that each row has as many stars as the order that it appears in?

It might help to launch another debugging session and visualize the runtime.

And I hope you can see the problem each passed from the outer loop, runs the inner loop 10 times.

Instead, the first pass should run the inner loop once, the second pass should run the inner loop

twice.

And so the amount of times the inner loop runs should depend on the index of the outer loop.

So the inner loop should keep running as long as J is smaller than I.

OK, this is great progress.

But why are there only one, two, three, four, nine lines?

Wow, another bug that we have to fix.

So we can launch another debugging session.

And by visualizing the runtime, the issue becomes clear, the first pass from the outer loop doesn't

do anything, so only nine lines from the pyramid shows up.

That's because one eye is zero and zero.

This condition is false.

So we need to make sure that Jay is less than or equal to I.

And perfect and displays ten rows each row has as many stars as the order that it appears in.

The first loop runs only once.

The second inner loop runs twice.

A third inner loop runs three times.

And pretty much the number of times the inner loop runs depends on the index of the outer loop.

And honestly, it's really satisfying seeing the code, working with your own eyes.

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