Head First Java a brain-Friendly Guide Kathy Sierra and Bert Bates



Download 17,18 Mb.
Pdf ko'rish
bet85/90
Sana22.06.2022
Hajmi17,18 Mb.
#693704
1   ...   82   83   84   85   86   87   88   89   90
Bog'liq
(Head Up) Kathy Sierra Bert Bates - Head First Java, 3rd Edition Early Release-O\'Reilly Media, Inc. (2021)

output:


++ --
Pre and Post Increment/Decrement Operator
The shortcut for adding or subtracting 1 from a variable.
x++;
is the same as:
x = x + 1;
They both mean the same thing in this context: “add 1 to the current
value of x” or “
increment
x by 1”
And:
x--;
is the same as:
x = x - 1;
Of course that’s never the whole story. The placement of the operator
(either before or after the variable) can affect the result. Putting the
operator 
before
the variable (for example, ++x), means, “
first
,
increment x by 1, and 
then
use this new value of x.” This only matters
when the ++x is part of some larger expression rather than just in a
single statement.
int x = 0; int z = ++x;
produces: x is 1, z is 1
But putting the ++ 
after
the x give you a different result:
int x = 0; int z = x++;


produces: x is 1, but 
z is 0
! z gets the value of x and 
then
x is
incremented.
The enhanced for loop
Beginning with Java 5.0 (Tiger), the Java language added a second kind of
for
loop called the 
enhanced for
, that makes it easier to iterate over all the
elements in an array or other kinds of collections (you’ll learn about 
other
collections in the next chapter). That’s really all that the enhanced for gives
you—a simpler way to walk through all the elements in the collection.
We’ll revisit the 
enhanced for loop
in the next chapter, when we talk about
collections that 
aren’t
arrays. (Later in the book we’ll be talking about a
newer, more super-charged way of looping called “streams”, stay tuned!)

Download 17,18 Mb.

Do'stlaringiz bilan baham:
1   ...   82   83   84   85   86   87   88   89   90




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