slide1 n.
Skip this Video
Loading SlideShow in 5 Seconds..
Microsoft ® Small Basic PowerPoint Presentation
Download Presentation
Microsoft ® Small Basic

Loading in 2 Seconds...

play fullscreen
1 / 9

Microsoft ® Small Basic - PowerPoint PPT Presentation

  • Uploaded on

Microsoft ® Small Basic. Branches and Subroutines. Estimated time to complete this lesson: 1 hour. Code Branches and Subroutines. In this lesson, you will learn how to:. Create subroutines by using Sub and EndSub statements. Branch your code by using Goto statements.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Microsoft ® Small Basic' - jennessa

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Microsoft® Small Basic

Branches and Subroutines

Estimated time to complete this lesson: 1 hour


Code Branches and Subroutines

In this lesson, you will learn how to:

  • Create subroutines by using Sub and EndSub statements.

Branch your code by using Goto statements.


You can instruct the computer to process a line of code out of sequence if you use the Gotostatement.

Sometimes, you may want the computer to break the flow and jump to another line of code while the program is running.

As you know, the computer runs a program by reading and processing the statements line by line, one at a time.

branching in small basic programs
Branching in Small Basic Programs

Let’s examine the Goto statement and its various parts by writing a program.

In this program, the lineQ: statement is called a label, which is similar to a bookmark. You can add as many labels as you want and name them whatever you want, as long as you don’t use the same name more than once.

The Goto statement instructs the computer to run the statements after the lineQ: label again only if the condition in the If statement is true.



Branching in Small Basic Programs

You can also use the Goto statement to make a program run forever.

Let’s see how Goto statements work by adding one to a familiar program.

This program will continue to run until someone clicks the Close (X) button in the top-right corner of the text window.

subroutines in small basic programs
Subroutines in Small Basic Programs

When we write programs, we often want the computer to run certain statements more than once. You can avoid writing the same statements over and over if you use subroutines in your programs.

By using a subroutine, you can run one or more statements with a single instruction. To create a subroutine, you use the Sub keyword, and then you give the subroutine a specific name. You end the subroutine by using the EndSub keyword.

Look at the following subroutine named PrintHour, which opens a text window and displays the current hour.

subroutines in small basic programs1
Subroutines in Small Basic Programs

Let’s gain a better understanding of subroutines by writing another program…

In this program, we use the Divide( ) statement torun (or “call”) the subroutine Divide from any location within the program.


let s summarize
Let’s Summarize…

Congratulations! Now you know how to:

  • Create a branch by using a Goto statement.
  • Create a subroutine by using a Sub..EndSub statement.
show what you know
Show What You Know

Write a program that opens a text window and then performs the following steps:

  • Asks the user for the name, temperature, rain status, and wind status of 10 cities.
  • Uses branching and subroutines to determine and display the total number of:
    • Cold Cities
    • Cool Cities
    • Warm Cities
    • Hot Cities
    • Rainy Cities
    • Windy Cities