If...Then command

thunderace7

New Member
In the manual, some instances of the If...then command show it terminated with an End if whilst others do not.
Is there an easy way to understand when to use an End if?
Thanks.
 

hippy

Ex-Staff (retired)
The END IF command is used to terminate a multi-line IF block -

Code:
If b0 = 1 Then
  Gosub UpdateOutputs
End If
When it is a single line IF, with the command or action on the same line as the IF, there should be no END IF -

Code:
If b0 = 1 Then Gosub UpdateOutputs
Though I am not sure there are such examples in the manuals, a multi-line block can be put on one line by using colon separators. Because it is still a multi-line block in essence that needs the END IF to terminate it. Note the colons after the THEN and before the END IF -

Code:
If b0 = 1 Then : Gosub UpdateOutputs : End If
 

westaust55

Moderator
For your future reference, it can also be worth having a look at the on-line web pages for the PICAXE BASIC commands (accessible from the NASIC COmmands link at the top of these forum pages) as the webpages are currently newer than the pdf manuals and may contain some improved descriptions and examples.

That appears to be the case for the IF...THEN comamnd structure. See: http://www.picaxe.com/BASIC-Commands/Program-Flow-Control/if/
Which shows structures and examples for both:
  • Single line options
  • Multiple line/block structured options
 
Top