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



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

"ShowA"
,
"ShowB"
,
"The Office"
,
"ShowC"
};
int
index =
0
;
while
(index < recommendations.
length
) {
String recommendation = recommendations[index];
if
(recommendation ==
"The Office"
) {
System.
out
.println(
"I'll watch this one:"
);
System.
out
.println(recommendation);
break
;
}
System.
out
.println(
"Not sure, incrementing..."
);
index++;
}
What do you think happens here?
Do we loop through every single recommendation? Do we stop at a certain
point? Why? Here’s the output of the program:
Not sure, incrementing...
Not sure, incrementing...
I'll watch this one:
The Office
See how we didn’t even get to 
ShowC
? That’s because of the magical
break; statement. It says that the loop is done right now , regardless of
anything else!
So basically, the break statement lets us kill our loop at any time for any
reason. No need to wait until we get back to the top and re-evaluate the
condition. This iteration is done, and we won’t go onto the next one. Any
code we wrote after the while loop can run now.
Continuing on
We’ve seen a while loop that goes forever. Then one that goes through
every letter of the alphabet. Then one that stops when it wants to watch


“The Office” (unsurprisingly).
There’s another Java keyword I feel I must mention. It’s called continue .
You know how break basically kills the loop? Dead, over?
continue says “don’t kill the loop, but skip this iteration.”
Move on to the next iteration. Nothing to see here.
Let’s say you want to print every letter of the alphabet, but not ‘F’. You just
hate that letter.

Download 3,91 Mb.

Do'stlaringiz bilan baham:
1   ...   29   30   31   32   33   34   35   36   ...   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