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
Welcome to exercise number six.
In this exercise, the output we're expecting is a right diagonal and hopefully our code can print something
remotely similar.
And you know what, that's not a bad start, at least compared to the last one, we have something to
work with, but like always, let's put some break points and visualize the run time.
Hopefully we can identify the first bug.
OK, so I as one is also one Apprentice star.
And there's the first bug, the first line prints many spaces with a start at the end, the second line
prints one less that amount a third line prints one, lets that amount onto the last line, prints only
the star.
And going back to our code, the amount of times the inner loop runs goes up with the outer loop counter.
Instead, it needs to go down with the outer loop counter.
So I should start by equaling five.
And the outer loop is going to keep running as long as I is bigger than or equal to one.
And we're going to decrease the counter after every run.
OK, relaunching the debugger.
I starts at five.
So the inner loop runs five times.
Until Jay exceeds five, breaking the inner loop prints a new line and the second pass equals four,
so the inner loop is going to run four times and this is perfect.
We're making progress.
OK.
Now, the next thing we want to do is only print the final star.
And how are we going to do that?
Let's find out, relaunched the debugger.
First pass equals five JS one, we don't want to print anything here.
Nothing here, nothing here.
We only want to print the star at the very last run one J equals a five.
Second pass equals four, once again, we don't want to print any stars, not until J.
Equals IV for.
So when Jay is less than I, we want to print two empty spaces.
Otherwise, we want to print the star.
All right, last time.
First, past equals five days less than that, so it going to print the white space.
And it's going to keep printing white space until I equals Jay.
Second pass equals four J once again is less than ISO, it's going to print space.
Until Jake equals eye for.
Third pass equals three white space, white space, and where J equals three, it prints a star.
And just like that, we debugged our code.
And it should print a nice right diagonal perfect.
Now you can feel free to run the code to your heart's content.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.