

If the first condition is true the code between the 'if condition then' and 'elseif condition then' command will be executed, otherwise the 'elseif' condition will be evaluated, and, if true, the code between 'elseif condition then' and 'end if' will be executed.Īdditional 'elseif' commands can be added and each will be evaluated in turn if no previous 'if condition then' or 'elseif conditon then' have not evaluated as true. Instead of an 'else' command it is possible to use an 'elseif' command and specify another condition. If the condition is false then program execution immediately continues after the 'end if' command. If the condition is true then the code between the 'if condition then' and 'end if' commands is executed and then program execution continues after the 'end if' command. After either sets of code are executed program execution will continue on the line after the 'end if'.Ī multi-line or block-structured 'if' command does not need to have an 'else' clause. When the condition evaluates as true the code between the 'if condition then' and 'else' commands is executed, otherwise the code between the 'else' and 'end if' command is executed. If the condition is true the current loop ( do.loop or for.next) is is prematurely ended, execution of the program will continue after the 'loop' or 'next' command.Ī multi-line or block-structured 'if' command is spread over multiple lines. If the condition is true, the program executes a gosub command to the label, jumping to the label, running until it comes to a return command, and then returning to the code after the 'if condition then gosub label' command. If the condition is true, the program flow jumps to the label specified and continues execution from there. This behaves in the same way as the 'if condition then label' command. IF pinC.0 = 1 OR b1 = 1 OR b2 = 3 THEN EXIT The left variable's value is compared with the right variable's value to determine if the condition is met. The variable's value is compared with the value to determine if the condition is met. The condition determine whether an action should be taken or not. The 'if' statement commands check the variable's values and inputs at the time the command is processed so it is normal to put the command within a program loop that regularly scans the input.

If not the command is ignored and program flow continues on the next line after the 'if' command. If the condition is met the associated command is executed. This is commonly known as having 'nested if statements'.Īn 'if' statment is used to test general variables (or input pins) for certain conditions. These command statements may include further single line and multi-line 'if' commands. Version History 1.0.Home > BASIC Commands > Program Flow Control > if >Ĭondition - The condition which will cause the associated command to be executed or not.Ĭondition - The condition which will cause the associated code commands to be executed or not.Ĭode - Command statements which will be executed dependant upon the evaluation of the condition. It should be quite straightforward to adapt this code to other simple network tasks. You may need to chmod +x cbget.bas if you wish to run it directly from the command line.

Port 80 is typically the default port for HTTP connections. If you want to retrieve a web page with a URL such as, the host you provide to cbget is and the path is the remainder of the URL: /Protocols/HTTP/1.1/spec.html. If a file is given, the content is saved to that file instead (note the clever use of file #0). If no file is given, the contents of the requested resource are printed to the console. Interactive input fields correspond directly to the command line arguments (pressing Return without entering a file name is the same as omitting that argument): >run As you can see from the following example, the As indicated above, it is possible to provide the same configuration via command line arguments. cbget.bas ]Ĭalled with no arguments or from within the Macintosh GUI version of Chipmunk Basic, cbget prompts the user for input interactively. It also provided an opportunity to learn more about HTTP.
Chipmunk basic if commands how to#
This program was written as an exercise to figure out what sockets were and how to work with them in Chipmunk Basic. Cbget stands for “Chipmunk Basic Getter,” because it’s a cbas program that gets web pages.
