C# 0 The Complete Reference


Some Variations on the for Loop



Download 4,07 Mb.
Pdf ko'rish
bet148/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   144   145   146   147   148   149   150   151   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Some Variations on the for Loop

The


for

is one of the most versatile statements in the C# language because it allows a wide 

range of variations. They are examined here.

Using Multiple Loop Control Variables

The


for

 loop allows you to use two or more variables to control the loop. When using 

multiple loop control variables, the initialization and increments statements for each 

variable are separated by commas. Here is an example:

// Use commas in a for statement.

using System;

class Comma {

  static void Main() {

    int i, j;

www.freepdf-books.com




PART I

C h a p t e r   5 :  

P r o g r a m   C o n t r o l   S t a t e m e n t s  

95

PART IPART I



    for(i=0, j=10; i < j; i++, j--)

      Console.WriteLine("i and j: " + i + " " + j);

  }

}

The output from the program is shown here:



i and j: 0 10

i and j: 1 9

i and j: 2 8

i and j: 3 7

i and j: 4 6

Here, commas separate the two initialization statements and the two iteration expressions. 

When the loop begins, both 


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   144   145   146   147   148   149   150   151   ...   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