C# 0 The Complete Reference


PART I C h a p t e r   2



Download 4,07 Mb.
Pdf ko'rish
bet80/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   76   77   78   79   80   81   82   83   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


PART I

C h a p t e r   2 :  

A n   O v e r v i e w   o f   C #  

29

PART IPART I



    for(count = 0; count < 5; count = count+1)

      Console.WriteLine("This is count: " + count);

    Console.WriteLine("Done!");

  }


}

The output generated by the program is shown here:

This is count: 0

This is count: 1

This is count: 2

This is count: 3

This is count: 4

Done!


In this example, 

count

 is the loop control variable. It is set to zero in the initialization portion 

of the 

for

. At the start of each iteration (including the first one), the conditional test 



count < 5

is performed. If the outcome of this test is true, the 



WriteLine( )

 statement is executed. Next, 

the iteration portion of the loop is executed, which adds 1 to 

count

. This process continues 

until

count

 reaches 5. At this point, the conditional test becomes false, causing the loop to 

terminate. Execution picks up at the bottom of the loop.

As a point of interest, in professionally written C# programs you will almost never see 

the iteration portion of the loop written as shown in the preceding program. That is, you 

will seldom see statements like this:

count = count + 1;

The reason is that C# includes a special increment operator that performs this operation. 

The increment operator is 

++

 (that is, two consecutive plus signs). The increment operator 

increases its operand by one. By use of the increment operator, the preceding statement can 

be written like this:

count++;

Thus, the 



for

 in the preceding program will usually be written like this:

for(count = 0; count < 5; count++)

You might want to try this. As you will see, the loop still runs exactly the same as it did before.

C# also provides a decrement operator, which is specified as 

– –

. This operator decreases 

its operand by one.


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   76   77   78   79   80   81   82   83   ...   1096




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