SlideShare a Scribd company logo
1 of 9
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.
Branching 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 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.  output
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 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 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. output
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 Write a program that opens a text window and then performs the following steps:  ,[object Object]

More Related Content

What's hot

5.1 sharing code
5.1   sharing code5.1   sharing code
5.1 sharing codeallenbailey
 
3.6 debugging aids
3.6   debugging aids3.6   debugging aids
3.6 debugging aidsallenbailey
 
Programming language environments
Programming language environmentsProgramming language environments
Programming language environmentsMr McAlpine
 
Fd223 cg223 evernote
Fd223 cg223 evernoteFd223 cg223 evernote
Fd223 cg223 evernoteSandra Markus
 
Hey Siri, open my PowerApp
Hey Siri, open my PowerAppHey Siri, open my PowerApp
Hey Siri, open my PowerAppPeter Heffner
 
Creating a Personalized ipad Wallpaper
Creating a Personalized ipad WallpaperCreating a Personalized ipad Wallpaper
Creating a Personalized ipad Wallpaperszanotti
 
Stepshot Intro
Stepshot IntroStepshot Intro
Stepshot IntroStepShot
 
2.6 flickr, image list, and network objects
2.6   flickr, image list, and network objects2.6   flickr, image list, and network objects
2.6 flickr, image list, and network objectsallenbailey
 

What's hot (12)

5.1 sharing code
5.1   sharing code5.1   sharing code
5.1 sharing code
 
3.6 debugging aids
3.6   debugging aids3.6   debugging aids
3.6 debugging aids
 
Small basic
Small basicSmall basic
Small basic
 
Programming language environments
Programming language environmentsProgramming language environments
Programming language environments
 
Fd223 cg223 evernote
Fd223 cg223 evernoteFd223 cg223 evernote
Fd223 cg223 evernote
 
Hey Siri, open my PowerApp
Hey Siri, open my PowerAppHey Siri, open my PowerApp
Hey Siri, open my PowerApp
 
Creating a Personalized ipad Wallpaper
Creating a Personalized ipad WallpaperCreating a Personalized ipad Wallpaper
Creating a Personalized ipad Wallpaper
 
Stepshot Intro
Stepshot IntroStepshot Intro
Stepshot Intro
 
2.6 flickr, image list, and network objects
2.6   flickr, image list, and network objects2.6   flickr, image list, and network objects
2.6 flickr, image list, and network objects
 
Small Basic - Branching and Loop
Small Basic - Branching and LoopSmall Basic - Branching and Loop
Small Basic - Branching and Loop
 
Java
JavaJava
Java
 
Html tutorial
Html tutorialHtml tutorial
Html tutorial
 

Viewers also liked

2.5 clock, desktop, and dictionary objects
2.5   clock, desktop, and dictionary objects2.5   clock, desktop, and dictionary objects
2.5 clock, desktop, and dictionary objectsallenbailey
 
2.3 exploring shapes
2.3   exploring shapes2.3   exploring shapes
2.3 exploring shapesallenbailey
 
2.1 graphics window
2.1   graphics window2.1   graphics window
2.1 graphics windowallenbailey
 
Basic logo-command
Basic logo-commandBasic logo-command
Basic logo-commanddat298
 
2.2 turtle graphics
2.2   turtle graphics2.2   turtle graphics
2.2 turtle graphicsallenbailey
 
In-bai tap logo_01 (hsinh)
  In-bai tap logo_01 (hsinh)  In-bai tap logo_01 (hsinh)
In-bai tap logo_01 (hsinh)saobiennt
 
Msw logo application user manual for teacher
Msw logo application user manual for teacherMsw logo application user manual for teacher
Msw logo application user manual for teacherfarah510
 
In-bai tap logo_02 -thu tuc (hs)
  In-bai tap logo_02 -thu tuc (hs)  In-bai tap logo_02 -thu tuc (hs)
In-bai tap logo_02 -thu tuc (hs)saobiennt
 
Logo primitives
Logo primitivesLogo primitives
Logo primitivessshaner88
 
Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Akshay Nagpurkar
 
In-bai tap logo_02 -thu tuc (gv)
  In-bai tap logo_02 -thu tuc (gv)  In-bai tap logo_02 -thu tuc (gv)
In-bai tap logo_02 -thu tuc (gv)saobiennt
 
Principles of programming languages. Detail notes
Principles of programming languages. Detail notesPrinciples of programming languages. Detail notes
Principles of programming languages. Detail notesVIKAS SINGH BHADOURIA
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming languageVasavi College of Engg
 

Viewers also liked (16)

2.5 clock, desktop, and dictionary objects
2.5   clock, desktop, and dictionary objects2.5   clock, desktop, and dictionary objects
2.5 clock, desktop, and dictionary objects
 
2.3 exploring shapes
2.3   exploring shapes2.3   exploring shapes
2.3 exploring shapes
 
2.1 graphics window
2.1   graphics window2.1   graphics window
2.1 graphics window
 
Basic logo-command
Basic logo-commandBasic logo-command
Basic logo-command
 
2.2 turtle graphics
2.2   turtle graphics2.2   turtle graphics
2.2 turtle graphics
 
In-bai tap logo_01 (hsinh)
  In-bai tap logo_01 (hsinh)  In-bai tap logo_01 (hsinh)
In-bai tap logo_01 (hsinh)
 
Msw logo
Msw logoMsw logo
Msw logo
 
Msw logo application user manual for teacher
Msw logo application user manual for teacherMsw logo application user manual for teacher
Msw logo application user manual for teacher
 
In-bai tap logo_02 -thu tuc (hs)
  In-bai tap logo_02 -thu tuc (hs)  In-bai tap logo_02 -thu tuc (hs)
In-bai tap logo_02 -thu tuc (hs)
 
Logo primitives
Logo primitivesLogo primitives
Logo primitives
 
Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3Ppl for students unit 1,2 and 3
Ppl for students unit 1,2 and 3
 
Geometria de las Tortugas
Geometria de las  TortugasGeometria de las  Tortugas
Geometria de las Tortugas
 
In-bai tap logo_02 -thu tuc (gv)
  In-bai tap logo_02 -thu tuc (gv)  In-bai tap logo_02 -thu tuc (gv)
In-bai tap logo_02 -thu tuc (gv)
 
Principles of programming languages. Detail notes
Principles of programming languages. Detail notesPrinciples of programming languages. Detail notes
Principles of programming languages. Detail notes
 
Logo
LogoLogo
Logo
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 

Similar to Microsoft Small Basic Branches Subroutines

C plus plus for hackers it security
C plus plus for hackers it securityC plus plus for hackers it security
C plus plus for hackers it securityCESAR A. RUIZ C
 
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docxLabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docxDIPESH30
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training reportRaushan Pandey
 
Using Python inside Programming Without Coding Technology (PWCT) Environment
Using Python inside Programming Without Coding Technology (PWCT) EnvironmentUsing Python inside Programming Without Coding Technology (PWCT) Environment
Using Python inside Programming Without Coding Technology (PWCT) EnvironmentMahmoud Samir Fayed
 
His162013 140529214456-phpapp01
His162013 140529214456-phpapp01His162013 140529214456-phpapp01
His162013 140529214456-phpapp01Getachew Ganfur
 
Introducing small basic
Introducing small basicIntroducing small basic
Introducing small basicAn I
 
AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2Dan D'Urso
 
Introducing small basic
Introducing small basicIntroducing small basic
Introducing small basicSara Samol
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!olracoatalub
 
ProgFund_Lecture_7_Intro_C_Sequence.pdf
ProgFund_Lecture_7_Intro_C_Sequence.pdfProgFund_Lecture_7_Intro_C_Sequence.pdf
ProgFund_Lecture_7_Intro_C_Sequence.pdflailoesakhan
 
Introducing small basic
Introducing small basicIntroducing small basic
Introducing small basicsom_nangia
 
Application development with Python - Desktop application
Application development with Python - Desktop applicationApplication development with Python - Desktop application
Application development with Python - Desktop applicationBao Long Nguyen Dang
 
Visual Programming
Visual ProgrammingVisual Programming
Visual ProgrammingBagzzz
 

Similar to Microsoft Small Basic Branches Subroutines (20)

C plus plus for hackers it security
C plus plus for hackers it securityC plus plus for hackers it security
C plus plus for hackers it security
 
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docxLabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
 
C language industrial training report
C language industrial training reportC language industrial training report
C language industrial training report
 
Using Python inside Programming Without Coding Technology (PWCT) Environment
Using Python inside Programming Without Coding Technology (PWCT) EnvironmentUsing Python inside Programming Without Coding Technology (PWCT) Environment
Using Python inside Programming Without Coding Technology (PWCT) Environment
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
 
C++ for hackers
C++ for hackersC++ for hackers
C++ for hackers
 
His162013 140529214456-phpapp01
His162013 140529214456-phpapp01His162013 140529214456-phpapp01
His162013 140529214456-phpapp01
 
Introducing small basic
Introducing small basicIntroducing small basic
Introducing small basic
 
AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2AVB201.2 Microsoft Access VBA Module 2
AVB201.2 Microsoft Access VBA Module 2
 
A tutorial on C++ Programming
A tutorial on C++ ProgrammingA tutorial on C++ Programming
A tutorial on C++ Programming
 
Introducing small basic
Introducing small basicIntroducing small basic
Introducing small basic
 
ID E's features
ID E's featuresID E's features
ID E's features
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!
 
Introducing Small Basic.pdf
Introducing Small Basic.pdfIntroducing Small Basic.pdf
Introducing Small Basic.pdf
 
ProgFund_Lecture_7_Intro_C_Sequence.pdf
ProgFund_Lecture_7_Intro_C_Sequence.pdfProgFund_Lecture_7_Intro_C_Sequence.pdf
ProgFund_Lecture_7_Intro_C_Sequence.pdf
 
Introducing small basic
Introducing small basicIntroducing small basic
Introducing small basic
 
My final requirement
My final requirementMy final requirement
My final requirement
 
Chapter 2- Prog101.ppt
Chapter 2- Prog101.pptChapter 2- Prog101.ppt
Chapter 2- Prog101.ppt
 
Application development with Python - Desktop application
Application development with Python - Desktop applicationApplication development with Python - Desktop application
Application development with Python - Desktop application
 
Visual Programming
Visual ProgrammingVisual Programming
Visual Programming
 

More from allenbailey

4.4 advanced games
4.4   advanced games4.4   advanced games
4.4 advanced gamesallenbailey
 
4.3 collision detection
4.3   collision detection4.3   collision detection
4.3 collision detectionallenbailey
 
4.2 responding to events
4.2   responding to events4.2   responding to events
4.2 responding to eventsallenbailey
 
4.1 playing with shapes
4.1   playing with shapes4.1   playing with shapes
4.1 playing with shapesallenbailey
 
3.5 the controls object
3.5   the controls object3.5   the controls object
3.5 the controls objectallenbailey
 
3.3 the math object
3.3   the math object3.3   the math object
3.3 the math objectallenbailey
 
3.2 stacks and arrays
3.2   stacks and arrays3.2   stacks and arrays
3.2 stacks and arraysallenbailey
 

More from allenbailey (7)

4.4 advanced games
4.4   advanced games4.4   advanced games
4.4 advanced games
 
4.3 collision detection
4.3   collision detection4.3   collision detection
4.3 collision detection
 
4.2 responding to events
4.2   responding to events4.2   responding to events
4.2 responding to events
 
4.1 playing with shapes
4.1   playing with shapes4.1   playing with shapes
4.1 playing with shapes
 
3.5 the controls object
3.5   the controls object3.5   the controls object
3.5 the controls object
 
3.3 the math object
3.3   the math object3.3   the math object
3.3 the math object
 
3.2 stacks and arrays
3.2   stacks and arrays3.2   stacks and arrays
3.2 stacks and arrays
 

Recently uploaded

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

Microsoft Small Basic Branches Subroutines

  • 1. Microsoft® Small Basic Branches and Subroutines Estimated time to complete this lesson: 1 hour
  • 2. 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.
  • 3. Branching 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.
  • 4. 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. output
  • 5. 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.
  • 6. 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.
  • 7. 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. output
  • 8. 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.
  • 9.
  • 10. Uses branching and subroutines to determine and display the total number of:

Editor's Notes

  1. Code:j = 1lineI:TextWindow.WriteLine(j)j = j + 1If j < 30 ThenGotolineQEndIf
  2. In the first line of this program, you create a variable that is named j, and you set its value to 1.Then you create a label that is named lineQ: with a colon (:) at the end.In the next line, you tell the computer to display the value of the j variable on the screen.Then you increase the value of the j variable by 1.In the fourth line, you determine whether the value of the j variable is smaller than 10.--If it is, you tell the computer to repeat the lines of code that follow the lineQ: label. In other words, you tell the computer to display the value of the j variable, increase its value by 1, and then determine whether that value is smaller than 10.--If the value of the j variable is not smaller than 10, you tell the computer to continue to the next part of the program (or to stop running the program if no more code exists).Code:j = 1lineQ:TextWindow.WriteLine(j)j = j + 1If j < 10 ThenGotolineQEndIf
  3. Solution:up:If i < 10 thenTextWindow.WriteLine("")TextWindow.Write(“What is the name of a city? ") city = TextWindow.Read()TextWindow.Write(“How warm is that city (in degrees Celsius)? ") temp = TextWindow.Read()TextWindow.Write(“Is it rainy (Y/N)? ") rainy = TextWindow.Read()TextWindow.Write(“Is it windy (Y/N)? ") windy = TextWindow.Read()'Calling subroutinessubtempCount()subrainyCount() subwindyCount()i = i + 1 If i = 10 ThensubOutput()EndIf EndIf Goto up Sub subtempCountIf temp <= 5 ThenColdCount = ColdCount + 1ElseIftemp <= 15 ThenCoolCount = CoolCount + 1 ElseIftemp <= 25 ThenWarmCount = WarmCount + 1 ElseHotCount = HotCount + 1 EndIfEndSubSub subRainyCountIf Rainy = "y" Or Rainy = "Y" ThenRainyCount = RainyCount + 1EndIfEndSubSub subWindyCountIf Windy = "y" or Windy = "Y" thenWindyCount = WindyCount + 1EndIfEndSub Sub subOutputTextWindow.WriteLine("")TextWindow.WriteLine("Number of cold cities: " + ColdCount) TextWindow.WriteLine("Number of cool cities: " + CoolCount) TextWindow.WriteLine("Number of warm cities: " + WarmCount)TextWindow.WriteLine("Number of hot cities: " + HotCount)TextWindow.WriteLine("Number of rainy cities: " + RainyCount)TextWindow.WriteLine("Number of windy cities: " + WindyCount) EndSub