View previous topic :: View next topic |
Author |
Message |
njepsen
Joined: 13 Aug 2007 Posts: 471
|
Posted: Tue Dec 12, 2023 3:34 am Post subject: 'Continue' in an IF END IF loop |
|
|
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 |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
Posted: Tue Dec 12, 2023 11:48 am Post subject: |
|
|
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 _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 1038
|
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
Posted: Tue Dec 12, 2023 12:41 pm Post subject: |
|
|
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 _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 1038
|
Posted: Tue Dec 12, 2023 12:46 pm Post subject: |
|
|
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 (updated) |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
Posted: Tue Dec 12, 2023 1:45 pm Post subject: |
|
|
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 |
|
|
EDC
Joined: 26 Mar 2014 Posts: 1038
|
Posted: Tue Dec 12, 2023 2:42 pm Post subject: |
|
|
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 (updated) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2289
|
Posted: Tue Dec 12, 2023 5:41 pm Post subject: Re: 'Continue' in an IF END IF loop |
|
|
njepsen wrote: | with an if - end if loop. |
Since when an If/then/else is a loop?
Ever tried hula hoop with a stick? |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2289
|
Posted: Wed Dec 13, 2023 2:22 pm Post subject: |
|
|
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
|
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
Posted: Wed Dec 13, 2023 2:37 pm Post subject: |
|
|
MWS
sorry, I read too fast. I see the #if ...
jp _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
|