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



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

'A'

'B'

'C'

'D'
}; 
int
i = 
0

while
(i < myArray.
length
) { 
System.
out
.println(myArray[i]); 


i++; 
}
//For loop
char
[] myArray = {
'A'
,
'B'
,
'C'
,
'D'
};
for
(
int
i =
0
; i < myArray.
length
; i++) {
System.
out
.println(myArray[i]);
}
“Holy shit!” – you, the reader
I mean look at it! It’s majestic! In that one line of code (the one that starts
with for ) we did the exact same 3 things that while loop did in 3 different
locations.
1. Declare an “index” variable that is used while looping.
2. Write the condition that determines when the loop should keep
going or stop.
3. Increase the index at the end of the loop.
I’ll admit it. A for loop is more confusing for beginners, especially so for
idiots, buffoons, and debutants. And no, I don’t know what that last word
means.
But you get very concise and easy-to-understand code once you get used to
it. And guess what? This is the type of loop you see 95% of the time in
Java.
That’s because the most common reason to loop is to go through every
element in a data set, like an array, and do something for each one. This is
simply the most concise way to do that.
Why and when to for loop?
99% of the time, you use a 
for
loop when you have an array (or some list)
of data. You need to do something to each of the items in the arrayor you
need to do something using each item in the array.
For each product in the cart, apply the coupon code to it.
For each horse in the race, calculate the odds of it winning.


For each depressing memory, cry for 1 hour.
Reverse, reverse!
It’s also easy to do different kinds of loops by adjusting the three sections of
the for loop. If you notice, those sections are indeed separated by
semicolons.
For example, maybe you want to go through the array in reverse . Here’s
what those 3 sections would specify:
1. Set the index’s initial value to the end of the array

Download 3,91 Mb.

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