{"id":60,"date":"2004-05-24T13:59:10","date_gmt":"2004-05-24T18:59:10","guid":{"rendered":"http:\/\/www.tigoe.com\/pcomp\/code2\/category\/basic-stamp\/60"},"modified":"2007-08-07T22:38:30","modified_gmt":"2007-08-08T03:38:30","slug":"branch","status":"publish","type":"post","link":"https:\/\/www.tigoe.com\/pcomp\/code\/pBasic\/60\/","title":{"rendered":"Branch"},"content":{"rendered":"<p>BRANCH allows branching to one of multiple subroutines depending on the value of a specified variable. It&#8217;s the equivalent of a case statement. PicBasic Pro also has a BRANCH statement, as does mBasic. It looks like this:<\/p>\n<pre>BRANCH value, [label1, label2, label3...]<\/pre>\n<p>\nIf value = 0, the program goes to label1. If value = 1, the program goes to label2. If value = 2, it goes to label3, and so forth.<\/p>\n<p>&nbsp;<\/p>\n<p>Here&#8217;s a BS2 program illustrating BRANCH:<\/p>\n<p>&nbsp;<\/p>\n<p><!--more--><\/p>\n<pre>\n'branch.bs2\n' program to illustrate branch statement\n' this program takes a range of numbers from 0 to 3\n' and branches to one of four different subroutines\n' based on which number it's given\n'\n'hardware:\n' rctime (analog) input on pin 7\n' digital outputs on pins 8 to 11\n' set up outs and ins:\noutput 8\noutput 9\noutput 10\noutput 11\ninput 7\n'set up variables:\npotVar var word        ' range from rctime\nhitVar var byte        ' potVar divided into a range from 0 - 3\ni var nib        ' variable for incrementing for-next loop\nmain:\n    ' get the rctime value:    \n    high 7\n    pause 1\n    rctime 7, 1, potVar\n    'divide potVar by one fourth its maximum value:\n    hitVar = potVar \/ 400\n    debug ?hitVar\n    'turn off all digial outs:\n    for i = 8 to 11\n        low i\n    next\n    \n    ' go to one of four subroutines \n    ' depending on value of hitvar:\n    branch hitvar, [one, two, three, four]\ngoto main\none:\n    high 8\ngoto main\ntwo:\n    high 9\ngoto main\nthree:\n    high 10\ngoto main\nfour:\n    high 11\ngoto main\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>BRANCH allows branching to one of multiple subroutines depending on the value of a specified variable&#8230;.  If value = 1, the program goes to label2.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-60","post","type-post","status-publish","format-standard","hentry","category-pBasic"],"_links":{"self":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/60","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/comments?post=60"}],"version-history":[{"count":0,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/posts\/60\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/media?parent=60"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/categories?post=60"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tigoe.com\/pcomp\/code\/wp-json\/wp\/v2\/tags?post=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}