what's the problem...when t=6 the break statement gets executed and the
control comes out of the for loop......

hence prints 6..

On Mon, Jun 20, 2011 at 12:05 AM, Oppilas <jatka.oppimi...@gmail.com> wrote:

> Sanjay,
> Whenever we encounter a break statement does not it means to take the
> program counter outside of the current loop.
> I am confused a little bit. Someone please clarify.
> See the following program
> #include<stdio.h>
> #include<stdlib.h>
> int main(){
>    int t=4;
>    for(int i=0;i<5;i++){
>    if(1){
>          if(t==6) break;
>          }
>          t++;
>    }
>   printf("%d",t);
>   /* Prints 6 */
>    return 0;
> }
>
> ~
> Oll
> On Jun 19, 6:05 pm, sanjay ahuja <sanjayahuja.i...@gmail.com> wrote:
> > i=4 is default case for but there is no break statement after default
> > case. There for all cases until break is encountered will be executed.
> > so i += 5;  makes i=9
> > i -= 4; will make i=5
> > and then break
> > so i is 5
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Sun, Jun 19, 2011 at 6:29 PM, sahil <sahil18...@gmail.com> wrote:
> > > #include<stdio.h>
> > > void main()
> > > { int i = 4;
> >
> > > switch (i)
> > > {
> >
> > > default: ;
> > > case 3:
> > > i += 5;
> > > if ( i == 8)
> > > {
> > > i++;
> > > if (i == 9) break;
> > > i *= 2;
> > > }
> > > i -= 4;
> > > break;
> >
> > > case 8:
> > > i += 5;
> > > break;
> > > }
> > > printf("i = %d\n", i);
> > > }
> >
> > > output:
> >
> > > i=5
> >
> > > how..........? can sme one explain...!!
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups "Algorithm Geeks" group.
> > > To post to this group, send email to algogeeks@googlegroups.com.
> > > To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> > > For more options, visit this group athttp://
> groups.google.com/group/algogeeks?hl=en.
> >
> > --
> > Sanjay Ahuja,
> > Analyst, Financing Prime Brokerage
> > Nomura Securities India Pvt. Ltd
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to