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



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

if
(letter ==
'F'
) {
continue
;
}
System.
out
.println(letter);
}
It might be a contrived example, but it’s a reminder that we need to be
careful inside loops that we don’t infinitely spin our wheels.
The doo doo while loop
Note that a loop doesn’t have to run at all. What if before we did the loop
on our alphabet, we set the index to a value other than 0? A value outside
the size of the alphabet?
int
index =
87
;
while
(index < alphabet.
length


Well that’s simply too high! The while loop sees the index isn’t less than
26, so it doesn’t run even once! Not a single letter is printed out.
That’s good though, right? No problem with that. The 
while
statement is
simple and does what it’s supposed to: runs code over and over again while
a certain condition is true.


Here’s comes the fun, doo doo doo doo
However, at some point the Java developers thought: why don’t we fix this?
Oh, it makes sense as-is, but why don’t we add another kind of loop for no
reason?
(Note: this actual conversation didn’t happen)
That’s when we get the “do-while” loop, or “doo doo” while loop, as I call
it. Because it’s stupid and no one uses it, except the one guy reading this
that is infuriated that I’m insulting his favorite language construct.
Here’s how it works:
I write some code. It’s run once. Then, we start a while loop. It might be run
again.
do
{
System.
out
.println(
"I hate that I exist."
);
}
while
(
false
);
What do you think would happen if we run this code? Take a guess inside
your little noggin.
“I hate that I exist” is print out to the screen once. Then, the condition is
evaluated at the end .
Since I literally wrote false (the opposite of true ), the loop doesn’t keep
going. One could argue the loop never started. This is the opposite of the
while loop, which looks at the condition at the beginning .
I’ll give you some more:

Download 3,91 Mb.

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