Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
computers:arduino:breeze [03-Jun-2019 13:40] – [Calling External Subroutines] Steve Joyntcomputers:arduino:breeze [02-Feb-2025 16:14] (current) – external edit 127.0.0.1
Line 167: Line 167:
 The word "goto" on line 100 is accepted by "if" as its second parameter, but otherwise ignored. The word "goto" on line 100 is accepted by "if" as its second parameter, but otherwise ignored.
  
-On line 200 there is a coding error. The command "goto" will always executed, even if the condition is false. Can you guess why? +On line 200 there is a coding error, but not a syntax error. The command "goto" will always executed, even if the condition is false. Can you guess why? 
 ==== Named Sections of Code ==== ==== Named Sections of Code ====
  
Line 174: Line 174:
 I propose to use the hash character "#" as the "command" to define a label. In many programming languages, the hash character indicates a comment, and so it is not executed by the interpreter. Labels also contain no executable code, so this feels intuitive to programmers, and is understood by many syntax highlighters.  I propose to use the hash character "#" as the "command" to define a label. In many programming languages, the hash character indicates a comment, and so it is not executed by the interpreter. Labels also contain no executable code, so this feels intuitive to programmers, and is understood by many syntax highlighters. 
  
-The first parameter will be the name of the label, and must be unique within the script. More parameters may be supplied, but will be ignored as comments, but beware of using [brackets] or (brackets) within the parameters as they will be executed as usual. It is recommended to enclose any comments in quotes.+The first parameter will be the name of the label, and must be unique within the script. If there are no parameters, the command does nothing at all. 
 + 
 +More parameters may be supplied, but will be ignored as comments, but beware of using [brackets] or (brackets) within the parameters as they will be executed as usual. It is recommended to enclose any comments in quotes
 + 
 +If the first parameter is "#", it does not need to be unique and it is ignored. This form can be used to continue the comment from the previous line, to describe this subroutine in more detail.
  
 <code> <code>
Line 186: Line 190:
  
 <code> <code>
-100 # CountDown "This is the entry point to this sub-routine"+100 # CountDown "This is the entry point to this section of code" 
 +105 # # "It counts down from 10 to 1, then signals 'Blast Off'"
 110 set count 10 110 set count 10
 200 # CountDownLoop 200 # CountDownLoop
Line 205: Line 210:
 BASIC has the keywords "gosub" and "return". The "gosub" command works like the "goto" command, but remembers where it came from, so that when a "return" command is encountered, execution continues with the line after the "gosub" command. BASIC has the keywords "gosub" and "return". The "gosub" command works like the "goto" command, but remembers where it came from, so that when a "return" command is encountered, execution continues with the line after the "gosub" command.
  
 +It is not possible to pass parameters to subroutines in BASIC using the "gosub" command, but you can define some variables before calling a subroutine, and that routine can return values by setting other variables. In this case it would be good to name the variables associated with the subroutine in a way that makes it obvious what they are related to, and also to prevent clashes with variables used by other subroutines.
 +
 +<code>
 +100 set AskUser.question "Which country do you come from?"
 +110 gosub AskUser
 +120 set AskUser.question "Why have you come here from "[ get AskUser.answer ]"?"
 +130 gosub AskUser
 +140 set AskUser.question "Are you a spy?"
 +150 gosub AskUser
 +160 display "I don't believe you!"
 +170 end
 +200 # AskUser "Keep asking a question until we get an answer"
 +210 display [ get AskUser.question ]
 +220 input AskUser.answer
 +230 if ( [ get AskUser.answer ] == "" ) goto AskUser
 +240 return
 +</code>
  
 ==== Calling External Subroutines ==== ==== Calling External Subroutines ====
  • computers/arduino/breeze.1559569249.txt.gz
  • Last modified: 02-Feb-2025 16:12
  • (external edit)