Re: How to exit a For-Next in a nested Switch statement?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



i do this too, there is convention that states that code should manipulate
the counter. if you don't care about convention, that's fine

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



"raican" <googlegroups@xxxxxxxxxxxx> wrote in message
news:1126636503.519346.173340@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> hi,
>
> the way i've exited for loops in the past is to set the loop variable
> to the max so the loop drops out naturally on it's next itteration.
>
> i.e.
> for (int i=0; i<=myArray.Length; i++)
> {
> if (myArray[i] == true)
> switch (i)
> {
> case 0 :
> ... do somehting
> i = myArray.Length + 1;
> break;
> case 1 :
> ... do somehting
> i = myArray.Length + 1;
> break;
> case 2 :
> ... do somehting
> i = myArray.Length + 1;
> break;
> }
> }
>
> i've never had any problems with this method.
>
> hope this helps
> :)
>


.



Relevant Pages

  • Re: Formatting in assembly
    ... the index counter in a loop isn't in the English Dictionary ... this is very known HLL convention, ... ; Convert Ascii to Integer: ... ; Convert Ascii to EAX: ...
    (alt.lang.asm)
  • Re: Counting nested loop iterations
    ... but x is used after the loop which creates it. ... Seems to be a matter of convention all the time. ... But I'm a happy camper with list-comps and the new ...
    (comp.lang.python)
  • Re: Euclids Algorithm in Python?
    ... >>test, but you're right, the plain while loop should work fine. ... As far as I understand the convention is it doesn't make ... sense to talk about a gcd if not all numbers are positive. ...
    (comp.lang.python)
  • RE: How to exit a For-Next in a nested Switch statement?
    ... I would put the body of the for loop into another function to aid ... switch ... do somehting ... exit the for loop; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to exit a For-Next in a nested Switch statement?
    ... if you want to exit the for loop in some cases but not in some ... you could put the loop and switch inside a method and use the return ...
    (microsoft.public.dotnet.languages.csharp)