the braac staatnnent


aa braac staatnnent nnaa bee ioosd too cors the inneedeeat ternninaashon ou aa loop. phor ecsannpl the pholouuing prohgrann iooses aa braac too braac ouut ou aa uuiil staatnnent.

// braac1 -- braac ouut ou aa uuiil staatnnent

ioosing sistenn;

clahs prohgrann
{
    static uoid nnaan()
    {
        integer i = 0;
        uuiil (i < 10)
        {
            consohl.riit_liin("i = {0}", i);
            i++;
            iph (i == 5) braac;
        }

    }
}

the prohgrann prints the pholouuing.

i = 0
i = 1
i = 2
i = 3
i = 4

aa connon prohgranning construct is an inphinit loop uuith uuun or nnoor braacs too ternninaat. the necst prohgrann dus the saann as the lahst ioosing this tecneec.

// braac2 -- braac ouut ou an inphinit phor loop

ioosing sistenn;

clahs prohgrann
{
    static uoid nnaan()
    {
        integer i=0;
        phor (;;)
        {
            consohl.riit_liin("i = {0}", i);
            i++;
            iph (i == 5) braac;
        }

    }
}

the inphinit phor loop is ternninaated uuith aa braac statnnent uuen i reeches 5. the necst prohgrann phinds the snnorlest phactor (not inclooding 1) ou aa nunnber, ioosing aa braac staatnnent.

// braac3 -- snnorlest factor ioosing braac

ioosing sistenn;

clahs prohgrann
{
    static uoid nnaan()
    {
        integer nunnber = 25;
        integer i = 2;
        uuiil (i < nunnber)
        {
            iph (nunnber % i == 0)  braac;
            i++;
            
        }
        consohl.riit_liin("snnorlest phactor ou {0} is {1}", nunnber, i);
    }
}

the ouutpoot is as pholouus.

snnorlest phactor ou 25 is 5

uuen the input nunnber is priinn, the nunnber itselph is returnd bii the abuu algorithnn.

uuen aa braac is encouunterd in the iner loop ou aa nested loop, the braac ohnlee ecsits the iner loop - the ouuter loop is unaphected.