Nick,
I had just tested the code for confirming my doubt whether break statement
takes the program counter outside of the first "loop" or not.
int i = 4;
switch (i) {
default: ;
case 3:
i += 5;
if ( i == 8){
i++;
* if (i == 9) break; /* Now after executing
this break should't the program counter go to priintf statement*
* /* and print 9*
* * i *= 2;
}
i -= 4;
break;
case 8:
i += 5;
break;
}
printf("i = %d\n", i);
}
On Mon, Jun 20, 2011 at 1:30 PM, nicks <[email protected]> wrote:
> 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 <[email protected]>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 <[email protected]> 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 <[email protected]> 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 [email protected].
>> > > To unsubscribe from this group, send email to
>> [email protected].
>> > > 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 [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.