If / Else if statement

General discussion on mikroBasic for dsPIC30/33 and PIC24.
Post Reply
Author
Message
nikhil
Posts: 35
Joined: 12 Jul 2009 06:24

If / Else if statement

#1 Post by nikhil » 15 Dec 2009 04:13

Hi !

I've used the following If Else if command and ME doesn't report any errors and appears to be working fine also, but after going thru certain post it appears it is not support..

Example:
sub procedure Timer2Int org $0022
if (portB.3=%1) then
LatB.3=%0
else if (PortB.3=%0) then
Latb.3=%1
end if
end if
IFS0.7=%0
end sub

Does ME support if / Else if ..if anyone has used..would appreciate a confirmation.

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

#2 Post by tihomir.losic » 15 Dec 2009 15:35

Hi,

Please post this question on our Support Desk:
http://www.mikroe.com/en/support/
And provide us with piece of code which demonstrate problem.

Regards,

Losic Tihomir
mikroElektronika [Support team]

octal
Posts: 534
Joined: 09 Feb 2005 14:15
Location: France
Contact:

Re: If / Else if statement

#3 Post by octal » 15 Dec 2009 15:46

nikhil wrote:Hi !

I've used the following If Else if command and ME doesn't report any errors and appears to be working fine also, but after going thru certain post it appears it is not support..

Example:
sub procedure Timer2Int org $0022
if (portB.3=%1) then
LatB.3=%0
else if (PortB.3=%0) then
Latb.3=%1
end if
end if
IFS0.7=%0
end sub

Does ME support if / Else if ..if anyone has used..would appreciate a confirmation.
why not ?
I dont see any problem with using Else IF (separated keywords).
between ELSE and ENDIF you can use any STATEMENT, and the IF/ENDIF can be used ... so an ELSE can be followed by an IF without problem. You only need to "close" your nested IF with and ENDIF and this is what you are doing. It works.


You should be careful.
Some other basic compilers let you use the ELESIF statement ... (in a single word, without space between ELSE and IF).
writing code like:

Code: Select all

IF cond1 then
...
ELSEIF  cond2
...
ELSEIF cond3
...
ELSE
...
ENDIF

this code is different from your previous code. This ELESEIF keyword let you check the condition and cascade tests in the same IF.
in mikroBasic, you should use the more cleaner SELECT CASE statement.

Regards
http://www.pocketmt.com

Post Reply

Return to “mikroBasic for dsPIC30/33 and PIC24 General”