Yes, 'break' aborts the inner-most loop/switch statement you're in. In fact,
the use you've shown below is quite common as far as I know.
- Marcel
On Fri, Jun 26, 2009 at 12:17 AM, cdb <
colin@...> wrote:
> I'm writing some I2C code for someone using the hardware MSSP on a
> 18F242.
>
> The following code works, but I'm not sure that it should.
>
> Break should only short circuit a loop, in error I've coded it into an
> IF statement that is inside a while loop - so whilst Break works for a
> while loop, should it work when in an IF statement inside a loop?
>
> Code below (note formatting may get mangled).
>
> void I2C_hwStop()
> {
> BYTE timeout = 50;
>
> SSPCON2 = SSPCON2 | (1<<PEN); // set stoP condition
>
> //In case the slave device gets stuck, we need to have a way of
> exiting.
> //otherwise we are stuck here until the plug is pulled!
> while (!(PIR1 & (1<<SSPIF)))
> {
> timeout --;
> if (timeout == 0)
> {
> break;
> }
> }
>
> PIR1 = PIR1 &~(1<<SSPIF); //clear completed flag
> }
> //end I2C_hwStop
>
> Thanks
>
> Colin
> --
> cdb, on 26/06/2009
>
>
>
>
>
>
> --
>
http://www.piclist.com PIC/SX FAQ & list archive
> View/change your membership options at
>
http://mailman.mit.edu/mailman/listinfo/piclist>
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist