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
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
Persian
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
All right, welcome to exercise number for this coach had printed diagonal, but if you run it, it
prints a line of stars.
Whoever wrote this code didn't do a very good job.
Now, at first glance, I'm not entirely sure how we're going to use the counters, A.J., to achieve
the desired output.
So what I'm going to do is use breakpoints to visualize the runtime and hopefully then I can observe
some kind of pattern.
So I'll launch the debugger.
Step through it.
OK, so I know that at this point I need to start a new line to stay consistent with the output, but
this inner loop runs 10 times.
It should only run once during the first pass and twice in the second pass, three times in the third
pass, etc., So the amount of times the inner loop runs depends on the outer loop index, not a static
value of ten.
So we'll put J is smaller than or equal to I.
And after the inner loop runs to completion, will print a new line.
Kate, let's try this out.
And the first pass is going to be a zero.
Jay is going to start at zero as well, so they're going to equal each other.
This condition is going to be true.
The inner loop runs once.
Now, just one, the inner loop breaks, starts a new line.
And now in the second pass, the inner loop is going to run twice.
Until Jay exceeds the outer loop index.
Prince, a new line, and eventually we're going to get our pyramid.
OK, cool.
Now, we don't want a pyramid, we want a diagonal.
So how are we going to do this?
Once again, I'm going to visualize the run time and hopefully I can see some kind of pattern.
OK, so it's fine if this one prince.
In the second pass, I don't want the first loop to print anything.
But we want the second interlude Apprentice star.
In the third pass, I don't want the first loop to print anything.
I don't want the second loop to print anything.
But we want the third in the loop to print star.
Now, I think I see the pattern when the inner loop counter equals the outer loop counter, that's when
we want to print the star.
So let's put our condition.
If Jay is equal to I.
We're going to print the star.
Run the code now.
Wait, what happened?
Let's visualize the runtime.
OK, so here Jake was I.
So it should print.
In the second pass, when Jay, smaller than I, nothing happens.
But when the indices are equal, it prints star.
I see, even though we can't print a Starwind Jay less than I, we still need to provide the empty space
needed to print the pyramid.
So we're going to add an statement.
Otherwise, when J is less than I.
We're going to print three spaces.
All right, let's see how this would look.
OK, so here Jay is equal to I, so we should print.
And the second pass, when Jay smarter than I print an empty space.
But when the indices are equal, it prints a star.
Now, the inner breaks moving on to the third pass.
I to zero prints and empty space, another empty space.
Princess Star, and if you keep going, eventually you're going to achieve a very nice diagonal.
As expected, it works beautifully.
We just debugged exercise number for.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.