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



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

if
(
true
) {
System.
out
.println(
"This line of code runs once."
);
}
while
(
true
) {
System.
out
.println(
"This line of code runs forever."
);
}
Does it make sense?


The 
while
loop, just like an 
if
statement, relies on a conditional, boolean
value (true or false) to know if the shit inside the curly braces should be
run.
And guess what? 
true
is always a 
true
value, unsurprisingly. So it
repeatedly evaluates to true, and runs until the heat death of the universe. Or
your computer catches fire.
A less infinite while loop
I have better examples than just an infinite loop in store for you. But, before
we start on these better examples, let’s create a variable. This variable will
be the current index of the array as we “loop through it”.
int
index = 
0
;
Remember, in an array of every character in the alphabet, the letter at index
0 is A, index 1 is B, etc.
Now, how many letters are in the alphabet? Don’t worry, once you create
the alphabet array, you can just use alphabet.length to get the size
remember? But it’s 26…
So, how can we write a 
while
loop that goes through every letter of the
alphabet, and prints each one out to the screen?
Think about it:
What would be inside the parentheses 
while (

)
to determine how
long we loop?
How do we know what letter to print to the screen?
Can you use the index variable we just made to address these 2 points?
Feel free to take some time (if you have any initiative at all), to see if you
can get this on your own.
If not, here’s the answer. Yes, I had to write out all the letters this time.

Download 3,91 Mb.

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