Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Exit a subroutine early

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

Bascom Member



Joined: 14 Apr 2018
Posts: 1

PostPosted: Sat Apr 14, 2018 10:49 pm    Post subject: Exit a subroutine early Reply with quote

I want to leave a subroutine early (before the final "end sub")

Here is what did not work for me:
I call a subroutine named "somesub".

Code:
sub somesub()


In the subroutine I perform some comparisons. If the comparisons are true, I want to leave the subroutine early so I don't waste time.

The compiler doesn't like it.

Code:

sub somesub()

blah
if a = b then
   do this
   do that
   end sub   'this is line 141 with error 123
end if

blah
blah

end sub
 


I get this error when trying to compile
Error : 123 Line : 141 END IF expected Sad

Evidently the compiler wants "if".... and then "end if" with no intermediate "end subs"
Evidently the compiler wants "sub".... and then "end sub" with no intermediate "end subs"

I am sure this is an easy fix and many have done it, but have not found on forum when I did search on "leave subroutine early" etc


Thanks sincerely for your time
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 495

poland.gif
PostPosted: Sun Apr 15, 2018 5:54 am    Post subject: Reply with quote

Open the Help (F1) and read "Exit" topic.

Code:
Sub Test()
 
 If A = 0 Then Exit Sub
 
 B = A  'B will not be assigned if A = 0 because Exit Sub
End sub
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 Old versions 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