Java for Fucking Idiots: Learn the Basics of Java Programming Without any experience!


while (index < alphabet. length



Download 3,91 Mb.
Pdf ko'rish
bet34/70
Sana02.04.2022
Hajmi3,91 Mb.
#524999
1   ...   30   31   32   33   34   35   36   37   ...   70
Bog'liq
Java for Fucking Idiots

while
(index < alphabet.
length
) {
char
letter = alphabet[index];
if
(letter ==
'F'
) {
continue
;
}
System.
out
.println(letter);
index = index +
1
;
}
We print out everything except ‘F’. The code after a continue statement is
never reached, instead we return to the top of the loop.
It’s like a break statement’s little brother. It “breaks” this iteration and goes
to the next, but it doesn’t kill the entire loop. Lil boi.
If you hated ‘F’ so much that you wanted to immediately stop printing out
letters, you’d go back to using continue .
A BUG? IN MY CODE?
There’s a problem with my last example. A “bug” as a programmer might
say, where something happens that you didn’t expect.
Did you notice it? Probably not. But can you see it now? Why might this
beautifully written code not do exactly what I described?
Hint: look at where the 
continue;
statement is. What doesn’t happen when
the letter is F?
Did you get it? Take a second.


Answer: the loop runs forever! Look what happens when the letter is an F;
we immediately skip the iteration using a 
continue;
and go to the next
iteration of the loop.
But what letter are we gonna look at next iteration? F. And the next one? F.
We never increased the value of the index!!! We’ll keep pulling F out of the
array since the index doesn’t change. Don’t make this mistake.
Here’s the fixed example. We increase the index immediately after pulling
the letter from the array:
while
(index < alphabet.
length
) {
char
letter = alphabet[index];
index = index +
1
;

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   30   31   32   33   34   35   36   37   ...   70




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish