C# 0 The Complete Reference


break  stops the  for



Download 4,07 Mb.
Pdf ko'rish
bet158/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   154   155   156   157   158   159   160   161   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

break

 stops the 



for

 loop as soon as a factor is found. The use of 



break

 in this situation 

prevents the loop from trying any other values once a factor has been found, thus preventing 

inefficiency.

When used inside a set of nested loops, the 

break

 statement will break out of only the 

innermost loop. For example:

// Using break with nested loops.

using System;

class BreakNested {

  static void Main() {

    for(int i=0; i<3; i++) {

      Console.WriteLine("Outer loop count: " + i);

      Console.Write("    Inner loop count: ");

      int t = 0;

      while(t < 100) {

        if(t == 10) break; // terminate loop if t is 10

        Console.Write(t + " ");

        t++;

      }


      Console.WriteLine();

    }


    Console.WriteLine("Loops complete.");

  }


}

This program generates the following output:

Outer loop count: 0

    Inner loop count: 0 1 2 3 4 5 6 7 8 9

Outer loop count: 1

    Inner loop count: 0 1 2 3 4 5 6 7 8 9

Outer loop count: 2

    Inner loop count: 0 1 2 3 4 5 6 7 8 9

Loops complete.

As you can see, the 



break

 statement in the inner loop causes only the termination of that 

loop. The outer loop is unaffected.

Here are two other points to remember about 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   154   155   156   157   158   159   160   161   ...   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