News:

Let's find out together what makes a PIC Tick!

Main Menu

Conditional exit from While ... Wend loop?

Started by trastikata, Nov 06, 2022, 09:36 AM

Previous topic - Next topic

trastikata

Hello all,

this is probably a silly question but I couldn't find any info about it. I was looking for a way to exit a While ... Wend loop with a condition i.e. If ... Then statement. The following code doesn't seem to produce the wanted result, any suggestions ... other than using different loop command  :) ?

QuoteWhile 1 = 1
   If bTemp = 1 Then Wend   
Wend

QuoteF1_000006 equ $ ; in [TEST.BAS] While 1 = 1
_lbl__2
F1_000007 equ $ ; in [TEST.BAS] if bTemp = 1 Then Wend
    movlw 1
    subwf bTemp,W,0
    bnz _lbl__5
_lbl__5
F1_000008 equ $ ; in [TEST.BAS] Wend
    bra _lbl__2
_lbl__3
F1_EOF equ $ ; TEST.BAS


atomix

While 1 = 1
   If bTemp = 1 Then Break
Wend

Dompie

Try the Break command

Johan

Edit OEPS @atomix answered already

trastikata

Thank you both.

I only used it in For ... Next loops for many years and never occurred to me it can be used in other loops, sometimes we are so stuck in the way we are used to do things.

This forum is great place to find help.

 

Dompie

.....yes, and the Continue command is also valid in while....wend

Johan