Branches execution to another location in the current screen. The command must name a BRANCH control on the current screen (or the BRANCH command fails and returns 0). When a BRANCH command is executed, both the command and shift to screen at the BRANCH control branched to are used.
BRANCH commands are normally used in conjunction with the IFTHENELSE command to test something and determine which way to proceed.
:SCREEN AFTERSIM
COMMAND,"",0,0,0,0,,,IFTHENELSE&TEST>Status Flag=0&BRANCH>BR1&BRANCH>BR1A
BRANCH,"BR1",0,0,0,0,,,,DECISION
BRANCH,"BR1A",0,0,0,0,,,IFTHENELSE&TEST>Status Flag=1&BRANCH>BR2&BRANCH>BR2A
BRANCH,"BR2",0,0,0,0,,,SPECIAL>MESSAGE|0|Sorry|You are doing poorly,\
DECISION
BRANCH,"BR2A",0,0,0,0,,,IFTHENELSE&TEST>Status Flag=2&BRANCH>BR3&BRANCH>BR3A
BRANCH,"BR3",0,0,0,0,,,SPECIAL>MESSAGE|0|Congratulations|You are doing well,\
DECISION
BRANCH,"BR3A",0,0,0,0,,,SPECIAL>MESSAGE|0|Wow|You are off the scale,DECISION
In this case a different message is put up and the same screen is then shifted to. It would also be possible to shift to a different screen.
You can also use branch commands to simply supplement an existing command. For example, suppose that you wished to give the user three choices, but execute a common set of commands after the choices have been made. The following screen uses BRANCH to do this:
:SCREEN DEFINE
TEXTONLY,"New Scenario Setup",0,5,100,0,C||18|B|255-0-0
BUTTON,"Start a new scenario",25,15,50,0,L,Ss,\
SIMULATE>READRUNCHG&\
SIMULATE>RUNNAME|?Name for the new scenario&BRANCH>SETUP,
BUTTON,"Build off of an existing scenario",25,25,50,0,L,Ss,\
SIMULATE>READRUNCHG|?Select scenario for basis&\
SIMULATE>RUNNAME|?Name for the new scenario&BRANCH>SETUP,
BUTTON,"Modify and rerun an existing scenario",25,35,50,0,,Mm,\
SIMULATE>RUNNAME|?Select the scenario to work with|E&\
SIMULATE>READRUNCHG|!&BRANCH>SETUP
BUTTON,"Exit back to main menu (cancel scenario \
creation)",20,68,60,0,L,EeXx,,MAIN
BRANCH,"SETUP",0,0,0,0,,,SIMULATE>SETVAL|FINAL TIME=1&MENU>RUN|O&\
SIMULATE>READRUNCHG|!&SIMULATE>SETVAL|FINAL TIME=100,RUN
In this case you get three choices, but regardless of what you choose, Vensim makes a short simulation that guarantees the existence of the run requested. Notice the READRUNCHG command after the simulate command. This is important because it guarantees that whatever conditions pertained in the run are restored for further modification. Finally, FINAL TIME is set to its normal value and the screen RUN is shifted to.