Positron Compiler Documentation

Break

Positron16 · Revision 1.1.3.5 · PDF pages 306–307

Break

Exit a For…Next, While…Wend or Repeat…Until loop prematurely.

' Break out of a For-Next loop when the count reaches 10

  Device = 24FJ64GA002             ' Select the device to compile for
  Declare Xtal = 32
  Declare Hserial_Baud = 9600       ' USART1 Baud rate
  Declare Hrsout1_Pin = PORTB.14    ' Select the pin for TX with USART1

  Dim MyByte as Byte

  CLKDIV = 0                        ' CPU peripheral clock ratio set to 1:1
  Write_OSCCONH(%00010000)          ' Enable PLL
  RPOR7 = 3                         ' Make PPS Pin RP14 U1TX
  For MyByte = 0 to 39             ' Create a loop of 40 revolutions
     HrsoutLn Dec MyByte             ' Display revolutions on the serial terminal
     If MyByte = 10 Then Break      ' Break out of the loop when MyByte = 10
     DelayMs 200                    ' Delay so we can see what's happening
  Next                              ' Close the For-Next loop
  HrsoutLn "Exited At ", Dec MyByte ' Display value when loop was broken
'
' Config fuses for internal oscillator with PLL
'
  Config Config1 = JTAGEN_OFF, GCP_OFF, GWRP_OFF, BKBUG_OFF, COE_OFF,_
                   ICS_PGx1, FWDTEN_OFF, WINDIS_OFF, FWPSA_PR128, WDTPOST_PS256
  Config Config2 = IOL1WAY_OFF, COE_OFF, IESO_OFF, FNOSC_FRCPLL,_
                   FCKSM_CSDCMD, OSCIOFNC_ON, POSCMOD_NONE
' Break out of a Repeat-Until loop when the count reaches 10

  Device = 24FJ64GA002             ' Select the device to compile for
  Declare Xtal = 32
  Declare Hserial_Baud = 9600       ' USART1 Baud rate
  Declare Hrsout1_Pin = PORTB.14    ' Select the pin for TX with USART1

  Dim MyByte as Byte

  CLKDIV = 0                        ' CPU peripheral clock ratio set to 1:1
  Write_OSCCONH(%00010000)          ' Enable PLL
  RPOR7 = 3                         ' Make PPS Pin RP14 U1TX
  MyByte = 0
  Repeat                           ' Create a loop
     HrsoutLn Dec MyByte             ' Display revolutions on the serial terminal
     If MyByte = 10 Then Break      ' Break out of the loop when MyByte = 10
     DelayMs 200                    ' Delay so we can see what's happening
     Inc MyByte
   Until MyByte > 39               ' Close the loop after 40 revolutions
  HrsoutLn "Exited At ", Dec MyByte ' Display value when loop was broken
'
' Config fuses for internal oscillator with PLL
'
  Config Config1 = JTAGEN_OFF, GCP_OFF, GWRP_OFF, BKBUG_OFF, COE_OFF,_
                   ICS_PGx1, FWDTEN_OFF, WINDIS_OFF, FWPSA_PR128, WDTPOST_PS256
  Config Config2 = IOL1WAY_OFF, COE_OFF, IESO_OFF, FNOSC_FRCPLL,_
                   FCKSM_CSDCMD, OSCIOFNC_ON, POSCMOD_NONE
View original PDF page 306Open page in PDFOriginal PDF page 306
' Break out of a While-Wend loop when the count reaches 10

  Device = 24FJ64GA002             ' Select the device to compile for
  Declare Xtal = 32
  Declare Hserial_Baud = 9600       ' USART1 Baud rate
  Declare Hrsout1_Pin = PORTB.14    ' Select the pin for TX with USART1

  Dim MyByte as Byte

  CLKDIV = 0                        ' CPU peripheral clock ratio set to 1:1
  Write_OSCCONH(%00010000)          ' Enable PLL
  RPOR7 = 3                         ' Make PPS Pin RP14 U1TX

  MyByte = 0
  While MyByte < 40               ' Create a loop of 40 iterations
     HrsoutLn Dec MyByte             ' Display iterations on the serial terminal
     If MyByte = 10 Then Break      ' Break out of the loop when MyByte = 10
     DelayMs 200                    ' Delay so we can see what's happening
     Inc MyByte
   Wend                              ' Close the loop
  HrsoutLn "Exited At ", Dec MyByte ' Display value when loop was broken
'
' Config fuses for internal oscillator with PLL
'
  Config Config1 = JTAGEN_OFF, GCP_OFF, GWRP_OFF, BKBUG_OFF, COE_OFF,_
                   ICS_PGx1, FWDTEN_OFF, WINDIS_OFF, FWPSA_PR128, WDTPOST_PS256
  Config Config2 = IOL1WAY_OFF, COE_OFF, IESO_OFF, FNOSC_FRCPLL,_
                   FCKSM_CSDCMD, OSCIOFNC_ON, POSCMOD_NONE

The Break command is similar to a GoTo but operates internally. When the Break command is encountered, the compiler will force a jump to the loop's internal exit label.

If the Break command is used outside of a For…Next, Repeat…Until, While…Wend or Do…Loop condition, an error will be produced.

See also : Continue, For…Next, While…Wend, Repeat…Until, Do…Loop.

View original PDF page 307Open page in PDFOriginal PDF page 307