Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

'Continue' in an IF END IF loop

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
njepsen

Bascom Member



Joined: 13 Aug 2007
Posts: 469

newzealand.gif
PostPosted: Tue Dec 12, 2023 3:34 am    Post subject: 'Continue' in an IF END IF loop Reply with quote

The examples don't show the use of CONTINUE with an if - end if loop. Is such use intended?
Code:


If A = B then
 'do something
  continue
elseif B = C then
        'do something
elseif D = E then
     'do something
end if


 


(BASCOM-AVR version : 2.0.8.6 )

_________________
Neil
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Tue Dec 12, 2023 11:48 am    Post subject: Reply with quote

hi,
yes is correct for me.

I use "continue" in a select case loop,
I wait for the return of a keyboard function which returns numbers from 1 to 24, in this loop the numbers 6 and 12 should not be taken into account so I "continue".
Code:

            Case 1 To 17                                    'les anomalies
            ' les touches ne sont pas comptabilisées tout de suite car il peut y avoir plusieurs anomalies
            'donc on les ranges dans un tableau de partiel() qui note le numero de la touche
                  If Clav = 6 or clav=12 Then                            'If Clav = 6  Then 'on ajoute une touche avec la version hmi
                     Continue                                    ' nv instruction à la place de gotosuite1
                  End If
     
                 'les touches 1 à 5, 7 à 12, 13 à 17, 19
                  Nbano = Nbano + 1                            'on vient de taper une anomalie
                  If Nbano > 6 Then                            'pas plus de 6 anomalies
                     For Y = 1 To 7
                        Partiel(y) = 0                         'remise à 0 des partiels
                     Next
                     Locate 16 , 31 : Lcd "Err frappe"
                     Call Buzzer(1)
                     Waitms 200
                     Locate 16 , 31 : Lcd Spc(10)
                     Nbano = 0
                   
             
 

jp Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Tue Dec 12, 2023 12:33 pm    Post subject: Reply with quote

Continue statement is allowed only inside the structure like loop.

Checking this can be made in one minute by testing this code in the simulator.




More curious is the next code. Even if E>0 the loop is never end and nothiung is printed so after Continue E dont get value of 100 and this is what Continue is intended for.

Code:
Do
If A = B then
 'do something
  continue
   E = 100
elseif B = C then
        'do something
  Continue
   D = 255
elseif D = E then
     'do something
  Continue
   D = 255
end if

Loop Until E > 0


Print "E=" ; E

End
 

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Tue Dec 12, 2023 12:41 pm    Post subject: Reply with quote

hi EDC
You right, but in my case it is in a loop ,

I forgot to precise and it works on more than 20 machines
do
'waiting for à key
select case.
if xxx
continue
endif
xxx
xxx
loop
jp Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Tue Dec 12, 2023 12:46 pm    Post subject: Reply with quote

I think I must write one more example because if first "If" match then program jump to the End If and dont check another condition.
The variable E will hold value of 100, not 255 even if, in the first "If" got 100.
So the "Continue" is not needed in the first post.

Code:
$regfile = "m328def.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 16
$framesize = 64
$sim

Dim A , B , C , D , E As Byte

'after reset Bascom set all variables to zero
'so A=B and B=C


If A = B then
 'do something
     E = 100
Elseif E = 100 Then
  E = 255
end if

Print "E=" ; E

End
 

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Tue Dec 12, 2023 1:45 pm    Post subject: Reply with quote

that sentence come from the help of visual basic windows

Quote:
You can transfer from a Do, For or While loop to the next iteration of that loop. Control immediately passes the loop condition test, which is equivalent to transferring to the For statement or the While statement or the Do or Loop statement containing the Until or While clause.

You can use Continue at any point in the loop that allows transfers. The rules for transferring control are identical to those for the GoTo instruction.


same in Basic Bascom (see the help) I think.
In my exemple I used "continue" to replace a goto
JP

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Tue Dec 12, 2023 2:42 pm    Post subject: Reply with quote

I want to remind that this is the bascom Forum and Bascom statements
So after the help:
Quote:
CONTINUE must be used inside a DO-LOOP, WHILE-WEND or FOR-NEXT loop.

The code jump is always inside the current loop.

Some times you want to skip some code without leaving a loop and there is Contuine comming to play. But sometimes conditions are match and You can solve this with a GOTO and a label but use of GOTO creates hard to understand code. For this reason some languages have the CONTINUE statement.


You can code somethings like this:
Dim A As Byte
Code:
Do
 If Somevariable = 0 Then
 Exit Do 'an option
 Continue 'an option
 Goto Exitthisloop
 A = 2
End If
Loop

 A = A - 1
Print A
Exitthisloop:
A = 200
Print A

End
 

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Tue Dec 12, 2023 5:41 pm    Post subject: Re: 'Continue' in an IF END IF loop Reply with quote

njepsen wrote:
with an if - end if loop.

Since when an If/then/else is a loop?

Ever tried hula hoop with a stick? Very Happy
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Wed Dec 13, 2023 8:26 am    Post subject: Reply with quote

Again MWS you rignt,
but in the help of bascom, the sample shows code without EXPLICIT loop
but that is split hairs (Chercher la petite bête) Wink

Code:
'-------------------------------------------------------------------------------------------------------------
'                                   REDO and CONTINUE example
'
'-------------------------------------------------------------------------------------------------------------
$regfile = "m128def.dat"
$hwstack = 32
$swstack = 16
$FrameSize = 24
 
 
dim b as byte
const test = 0
 
#if test = 0
  for b = 1 to 10
'when REDO is used, the code will continue here
    print b
    if b = 3 then
        continue                                             ' when b becomes 3,  the code will continue at the NEXT statement
    end if
    if b = 9 then exit for
    if b = 8 then
        redo                                               ' when b becomes 8, the code will continue after the FOR statement, it will not increase the variable B !
    'so in this example the loop will be forever
    end if
    print b
  'code continues here when CONTINUE is used
  next
 
#elseif test = 1
  b = 0
  do
    incr b
    if b = 2 then
        continue
    elseif b = 3 then
        redo
    end if
  loop until b > 5
 
#elseif test = 2
  b = 0
  while b < 5
    incr b
    if b = 2 then
        continue
    elseif b = 3 then
        redo
    end if
  wend
#endif
end
 

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Wed Dec 13, 2023 2:22 pm    Post subject: Reply with quote

Duval JP wrote:
but in the help of bascom, the sample shows code without EXPLICIT loop

What other loop, not existent in this sample, would you consider to be 'EXPLICIT' then?

From the code you've posted and which is found in the help, I see three clear and unmistakable loops.
I would say these are explicit.

1st loop
Code:
  for b = 1 to 10
  next

2nd loop
Code:
  do
  loop until b > 5

3rd loop
Code:
  while b < 5
  wend
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Wed Dec 13, 2023 2:37 pm    Post subject: Reply with quote

MWS
sorry, I read too fast. I see the #if ...

Crying or Very sad jp

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum