SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 1 hour
Conditions and Loops In this lesson, you will learn how to: Write programs that carry out different instructions based on whether one or more logical conditions are true.  Write programs that repeat instructions until a specific event occurs.
Conditions in Small Basic Programs Let’s look at the following program: Notice that this program contains the If, Then, and EndIf keywords. This program instructs the computer to display "Happy New Year" only if today is January 1st.  Would you like to specify conditions that control how your program runs (or whether it runs at all)?
Conditions in Small Basic Programs Now, let’s write a program in which you specify an alternate action to perform if the condition is false. Depending on when you run the program, the computer displays one of the following results:
Conditions in Small Basic Programs In programming, you can do that same thing in more than one way. As a programmer, you can choose the best way. Both programs give the same result, but you can use fewer If, Then, and EndIf keywords if you use the Else keyword. In this example, you might have noticed that the second condition in the program repeats a lot of information in the first condition.  Let’s reduce the repetition by using the Else keyword.
Let’s look at another example… Conditions in Small Basic Programs output You are writing a complex program, and you want to check whether the user typed an even number or an odd number. Notice the use of If, Then, Else, and EndIf in the program.
Conditions in Small Basic Programs When you write a program, you can specify as many conditions as you want by using the ElseIf keyword. You can also specify one or more operations for the computer to perform, depending on which condition is true when your program is run. Let’s look at this with an example. In this example, each condition contains a unique statement that the computer evaluates. When the computer evaluates a statement as true, the computer performs the operation for that condition and then proceeds to the end.
Loops in Small Basic Programs You can use a For loop if you know how many times you want the computer to repeat the instructions. You can use aWhileloop if you want the program to repeat the instructions until a specific condition is true. You can use a loop to instruct the computer to run one or more statements more than once. So, let’s explore some loop statements…
Loops in Small Basic Programs In this example, the variable contains a value that increases by 1 every time that the loop runs. Let’s start by writing a program that contains a For..EndFor loop.  In general, you use a For..EndFor loop to run code a specific number of times. To manage this type of loop, you create a variable that tracks how many times the loop has run. Click the               button on the Toolbar.
Loops in Small Basic Programs Let’s use this concept to print the multiplication table for the number 5. output
Loops in Small Basic Programs In the previous example, the value of the counter variable in a For loop increases by 1 every time the loop runs. However, you can increase the value by another number if you  use the Step keyword. For example, you can increase the value by 2 if you write the following code:
Loops in Small Basic Programs When you create a While loop, you specify a condition that is true when the loop starts. But the computer evaluates the condition every time that the loop repeats. When the condition becomes false, the loop stops. If you don’t know the loop count before you write a program, you can create a While loop instead of a For loop. Let’s write the following program to demonstrate the While loop:
Let’s Summarize… Congratulations! Now you know how to: Write programs that evaluate logical conditions and perform operations based on those results. Write programs that repeat one or more instructions either a specific number of times or based a logical condition.
Show What You Know Create a program to convert one or more student scores from a percentage to a letter grade. First, ask the user to specify how many grades will be calculated. Then ask the user to specify the first percentage, and convert it to a letter grade based on the following criteria: ,[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

2.4 sound, program, and text objects
2.4   sound, program, and text objects2.4   sound, program, and text objects
2.4 sound, program, and text objectsallenbailey
 
Programming language environments
Programming language environmentsProgramming language environments
Programming language environmentsMr McAlpine
 
Stepshot Intro
Stepshot IntroStepshot Intro
Stepshot IntroStepShot
 
Evaluation of computer based instruction
Evaluation of computer based instructionEvaluation of computer based instruction
Evaluation of computer based instructionAyoob Alshukaili
 
Android application (how to change the background) tutorial #3
Android application (how to change the background) tutorial #3Android application (how to change the background) tutorial #3
Android application (how to change the background) tutorial #3Yasmine Sherif EL-Adly
 
Android application (how to add a splash screen with timer) tutorial #4
Android application (how to add a splash screen with timer) tutorial #4Android application (how to add a splash screen with timer) tutorial #4
Android application (how to add a splash screen with timer) tutorial #4Yasmine Sherif EL-Adly
 

Was ist angesagt? (14)

Small basic
Small basicSmall basic
Small basic
 
2.4 sound, program, and text objects
2.4   sound, program, and text objects2.4   sound, program, and text objects
2.4 sound, program, and text objects
 
Programming language environments
Programming language environmentsProgramming language environments
Programming language environments
 
Java
JavaJava
Java
 
Small Basic - Branching and Loop
Small Basic - Branching and LoopSmall Basic - Branching and Loop
Small Basic - Branching and Loop
 
Stepshot Intro
Stepshot IntroStepshot Intro
Stepshot Intro
 
Q basic ch
Q basic chQ basic ch
Q basic ch
 
SAP OSS note search
SAP OSS note searchSAP OSS note search
SAP OSS note search
 
2.1.8 clean code and debugging
2.1.8 clean code and debugging2.1.8 clean code and debugging
2.1.8 clean code and debugging
 
Evaluation of computer based instruction
Evaluation of computer based instructionEvaluation of computer based instruction
Evaluation of computer based instruction
 
Visual Rhetoric March 4th
Visual Rhetoric March 4thVisual Rhetoric March 4th
Visual Rhetoric March 4th
 
Android application (how to change the background) tutorial #3
Android application (how to change the background) tutorial #3Android application (how to change the background) tutorial #3
Android application (how to change the background) tutorial #3
 
ChatCrypt
ChatCryptChatCrypt
ChatCrypt
 
Android application (how to add a splash screen with timer) tutorial #4
Android application (how to add a splash screen with timer) tutorial #4Android application (how to add a splash screen with timer) tutorial #4
Android application (how to add a splash screen with timer) tutorial #4
 

Andere mochten auch

2.1 graphics window
2.1   graphics window2.1   graphics window
2.1 graphics windowallenbailey
 
2.3 exploring shapes
2.3   exploring shapes2.3   exploring shapes
2.3 exploring shapesallenbailey
 
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
 
Logo primitives
Logo primitivesLogo primitives
Logo primitivessshaner88
 
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
 
4.4 advanced games
4.4   advanced games4.4   advanced games
4.4 advanced gamesallenbailey
 
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
 
Guia rápida de comandos de micromundos
Guia rápida de comandos de micromundosGuia rápida de comandos de micromundos
Guia rápida de comandos de micromundosYovany Garcia
 
Proyecto 1 en micromundos 24 mar2015
Proyecto 1 en micromundos   24 mar2015Proyecto 1 en micromundos   24 mar2015
Proyecto 1 en micromundos 24 mar2015lisvancelis
 
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
 
Proyecto 2 en micromundos 07 abr2015
Proyecto 2 en micromundos   07 abr2015Proyecto 2 en micromundos   07 abr2015
Proyecto 2 en micromundos 07 abr2015lisvancelis
 

Andere mochten auch (20)

2.1 graphics window
2.1   graphics window2.1   graphics window
2.1 graphics window
 
2.3 exploring shapes
2.3   exploring shapes2.3   exploring shapes
2.3 exploring shapes
 
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
 
Logo primitives
Logo primitivesLogo primitives
Logo primitives
 
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)
 
Logo
LogoLogo
Logo
 
4.4 advanced games
4.4   advanced games4.4   advanced games
4.4 advanced games
 
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
 
1.3 variables
1.3   variables1.3   variables
1.3 variables
 
Guia rápida de comandos de micromundos
Guia rápida de comandos de micromundosGuia rápida de comandos de micromundos
Guia rápida de comandos de micromundos
 
Proyecto 1 en micromundos 24 mar2015
Proyecto 1 en micromundos   24 mar2015Proyecto 1 en micromundos   24 mar2015
Proyecto 1 en micromundos 24 mar2015
 
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)
 
Proyecto 2 en micromundos 07 abr2015
Proyecto 2 en micromundos   07 abr2015Proyecto 2 en micromundos   07 abr2015
Proyecto 2 en micromundos 07 abr2015
 
PROGRAMANDO CON MSWLOGO
PROGRAMANDO CON MSWLOGOPROGRAMANDO CON MSWLOGO
PROGRAMANDO CON MSWLOGO
 
Guia Lenguaje Logo
Guia Lenguaje Logo Guia Lenguaje Logo
Guia Lenguaje Logo
 

Ähnlich wie 1.4 conditions and loops

Cis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingCis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingHamad Odhabi
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxXhelalSpahiu
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving TechniquesAshesh R
 
Visual Programming
Visual ProgrammingVisual Programming
Visual ProgrammingBagzzz
 
PYTHON NOTES
PYTHON NOTESPYTHON NOTES
PYTHON NOTESNi
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Syed Farjad Zia Zaidi
 
learn computer science.ppt
learn computer science.pptlearn computer science.ppt
learn computer science.pptfaithola1
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxmaheshnanda14
 
Final requirement for programming-Bonifacio, Mary Clemence
Final requirement for programming-Bonifacio, Mary ClemenceFinal requirement for programming-Bonifacio, Mary Clemence
Final requirement for programming-Bonifacio, Mary Clemenceclemencebonifacio
 
Introduction to programming by MUFIX Commnity
Introduction to programming by MUFIX CommnityIntroduction to programming by MUFIX Commnity
Introduction to programming by MUFIX Commnitymazenet
 
C++ Tutorial
C++ TutorialC++ Tutorial
C++ Tutorialfreema48
 
Introduction to computer science ch3 programming
Introduction to computer science ch3 programmingIntroduction to computer science ch3 programming
Introduction to computer science ch3 programmingMohamed Essam
 
Software Testing Introduction (Part 1)
Software Testing Introduction (Part 1)Software Testing Introduction (Part 1)
Software Testing Introduction (Part 1)Thapar Institute
 
CIST 1400, Introduction to Computer Programming Programmi.docx
 CIST 1400, Introduction to Computer Programming Programmi.docx CIST 1400, Introduction to Computer Programming Programmi.docx
CIST 1400, Introduction to Computer Programming Programmi.docxMARRY7
 
classVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxclassVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxssusere336f4
 

Ähnlich wie 1.4 conditions and loops (20)

Cis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programmingCis 1403 lab1- the process of programming
Cis 1403 lab1- the process of programming
 
Chapter 2- Prog101.ppt
Chapter 2- Prog101.pptChapter 2- Prog101.ppt
Chapter 2- Prog101.ppt
 
An Introduction To Python - WHILE Loop
An Introduction To  Python - WHILE LoopAn Introduction To  Python - WHILE Loop
An Introduction To Python - WHILE Loop
 
03b loops
03b   loops03b   loops
03b loops
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptx
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
Visual Programming
Visual ProgrammingVisual Programming
Visual Programming
 
PYTHON NOTES
PYTHON NOTESPYTHON NOTES
PYTHON NOTES
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
 
learn computer science.ppt
learn computer science.pptlearn computer science.ppt
learn computer science.ppt
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptx
 
Final requirement for programming-Bonifacio, Mary Clemence
Final requirement for programming-Bonifacio, Mary ClemenceFinal requirement for programming-Bonifacio, Mary Clemence
Final requirement for programming-Bonifacio, Mary Clemence
 
Introduction To Programming (2009 2010)
Introduction To Programming (2009 2010)Introduction To Programming (2009 2010)
Introduction To Programming (2009 2010)
 
Introduction to programming by MUFIX Commnity
Introduction to programming by MUFIX CommnityIntroduction to programming by MUFIX Commnity
Introduction to programming by MUFIX Commnity
 
programming.ppt
programming.pptprogramming.ppt
programming.ppt
 
C++ Tutorial
C++ TutorialC++ Tutorial
C++ Tutorial
 
Introduction to computer science ch3 programming
Introduction to computer science ch3 programmingIntroduction to computer science ch3 programming
Introduction to computer science ch3 programming
 
Software Testing Introduction (Part 1)
Software Testing Introduction (Part 1)Software Testing Introduction (Part 1)
Software Testing Introduction (Part 1)
 
CIST 1400, Introduction to Computer Programming Programmi.docx
 CIST 1400, Introduction to Computer Programming Programmi.docx CIST 1400, Introduction to Computer Programming Programmi.docx
CIST 1400, Introduction to Computer Programming Programmi.docx
 
classVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptxclassVI_Coding_Teacher_Presentation.pptx
classVI_Coding_Teacher_Presentation.pptx
 

Mehr von allenbailey

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
 
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
 

Mehr von allenbailey (7)

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
 
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
 

Kürzlich hochgeladen

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
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
 
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
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 

Kürzlich hochgeladen (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
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
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
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
 
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)
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 

1.4 conditions and loops

  • 1. Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 1 hour
  • 2. Conditions and Loops In this lesson, you will learn how to: Write programs that carry out different instructions based on whether one or more logical conditions are true. Write programs that repeat instructions until a specific event occurs.
  • 3. Conditions in Small Basic Programs Let’s look at the following program: Notice that this program contains the If, Then, and EndIf keywords. This program instructs the computer to display "Happy New Year" only if today is January 1st.  Would you like to specify conditions that control how your program runs (or whether it runs at all)?
  • 4. Conditions in Small Basic Programs Now, let’s write a program in which you specify an alternate action to perform if the condition is false. Depending on when you run the program, the computer displays one of the following results:
  • 5. Conditions in Small Basic Programs In programming, you can do that same thing in more than one way. As a programmer, you can choose the best way. Both programs give the same result, but you can use fewer If, Then, and EndIf keywords if you use the Else keyword. In this example, you might have noticed that the second condition in the program repeats a lot of information in the first condition. Let’s reduce the repetition by using the Else keyword.
  • 6. Let’s look at another example… Conditions in Small Basic Programs output You are writing a complex program, and you want to check whether the user typed an even number or an odd number. Notice the use of If, Then, Else, and EndIf in the program.
  • 7. Conditions in Small Basic Programs When you write a program, you can specify as many conditions as you want by using the ElseIf keyword. You can also specify one or more operations for the computer to perform, depending on which condition is true when your program is run. Let’s look at this with an example. In this example, each condition contains a unique statement that the computer evaluates. When the computer evaluates a statement as true, the computer performs the operation for that condition and then proceeds to the end.
  • 8. Loops in Small Basic Programs You can use a For loop if you know how many times you want the computer to repeat the instructions. You can use aWhileloop if you want the program to repeat the instructions until a specific condition is true. You can use a loop to instruct the computer to run one or more statements more than once. So, let’s explore some loop statements…
  • 9. Loops in Small Basic Programs In this example, the variable contains a value that increases by 1 every time that the loop runs. Let’s start by writing a program that contains a For..EndFor loop. In general, you use a For..EndFor loop to run code a specific number of times. To manage this type of loop, you create a variable that tracks how many times the loop has run. Click the button on the Toolbar.
  • 10. Loops in Small Basic Programs Let’s use this concept to print the multiplication table for the number 5. output
  • 11. Loops in Small Basic Programs In the previous example, the value of the counter variable in a For loop increases by 1 every time the loop runs. However, you can increase the value by another number if you use the Step keyword. For example, you can increase the value by 2 if you write the following code:
  • 12. Loops in Small Basic Programs When you create a While loop, you specify a condition that is true when the loop starts. But the computer evaluates the condition every time that the loop repeats. When the condition becomes false, the loop stops. If you don’t know the loop count before you write a program, you can create a While loop instead of a For loop. Let’s write the following program to demonstrate the While loop:
  • 13. Let’s Summarize… Congratulations! Now you know how to: Write programs that evaluate logical conditions and perform operations based on those results. Write programs that repeat one or more instructions either a specific number of times or based a logical condition.
  • 14.
  • 15. If the percentage is less than 75 but more than or equal to 60, convert it to a B.
  • 16. If the percentage is less than 60 but more than or equal to 35, convert it to a C.
  • 17. If the percentage is less than 35, convert it to a D.

Hinweis der Redaktion

  1. In Small Basic, you use the Clockobject to determine the current date and time. You use theIf keyword to specify a condition that the computer evaluates to determine whether it should perform a particular operation. You use the Then keyword to specify what operation or operations the computer should perform if the condition is true. If the condition is false, the computer skips the operation or operations and proceeds to the next line of the program. You use the EndIf keyword to indicate that the computer should proceed to the next line of the program regardless of whether the condition was true. In this example, you use the If keyword specify the condition that today is the first day of the first month of the year (January). You use the Then keyword to specify that, if today is the first day of the first month, the computer should run the WriteLine operation. If today is not the first day of the first month, the computer should skip the operation and proceed to the EndIf line of the program.Code:If Clock.Day = 1 And Clock.Month = 1 ThenTextWindow.WriteLine("Happy New Year")EndIf
  2. Code:If Clock.Hour < 12 thenTextWindow.WriteLine("Did you have your breakfast?")EndIfIf Clock.Hour > 12 thenTextWindow.WriteLine("Did you have your lunch?")EndIf
  3. In this program, you specify a condition and an operation to perform if that condition is true. Then you specify a second condition and a second operation to perform if the second condition is true. However, the first condition is true only if the second condition is false, and the second condition is true only if the first condition is false. Therefore, you don’t need to specify the second condition because the computer can determine which operation to perform based only on the first condition. Instead of giving the computer two conditions to evaluate, you can specify that the computer should perform the first operation if the first condition is true and the computer should perform the second operation if the first condition is false. The result of both approaches is the same. This example shows that you can do the same thing in different ways in programming. It’s up to you!Code:If Clock.Hour < 12 ThenTextWindow.WriteLine("Did you have your breakfast?")ElseTextWindow.WriteLine("Did you have your lunch?")EndIf
  4. In this program, you first use the WriteLine operation to display "Multiplication Table" on the screen.Then you create the variable “number” to store the value of 5.Then you create a For loop with the variable “a” to ensure the WriteLine operation will run 10 times.You use the WriteLine operation to display the following elements in this order:--the value that is stored in the “a” variable--the multiplication sign--the value that is stored in the “number” variable--the equals sign--the products of the values of the “a” and “number” variablesCode:TextWindow.WriteLine("Multiplication Table")number = 5For a = 1 to 10TextWindow.WriteLine(a + " x " + number + " = " + a * number)EndFor
  5. You can even decrease the value of the loop variable every time that the code runs if you use the Step keyword but specify a negative number. For example, you can write a program that counts backward from 10 to 1 on the screen if you assign the value of -1 to the Step keyword.Code:TextWindow.WriteLine("Multiply odd numbers by 5:")number = 5For a = 1 to 10 Step 2TextWindow.WriteLine(a + " x " + number + " = " + a * number)EndFor
  6. In this example, you first create the “a” variable and set its value to 10.  Next, you create a While loop with a condition that the value of the “a” variable is smaller than or equal to 100. Because you just set the value of that variable to 10, the condition is true when the loop starts.You use the WriteLine operation to display the value of the “a” variable every time that the loop runs.In the next statement, you increase the value of the “a” variable by 10 every time that the loop runs.The loop stops after it runs 10 times because the value of the “a” variable becomes larger than 100. Code:a = 10While (a <= 100)TextWindow.WriteLine(a) a = a +10EndWhile
  7. Solution:TextWindow.Write(“How many student grades would you like to calculate?")number = TextWindow.Read()n = 1While n <= numberTextWindow.Write(“What is the student’s percentage? ") percentage = TextWindow.Read()If percentage >= 75 Then TextWindow.WriteLine("The student’s grade is A.")ElseIf percentage < 75 And percentage >= 60 Then TextWindow.WriteLine("The student’s grade is B.")ElseIf percentage < 60 And percentage >= 35 Then TextWindow.WriteLine("The student’s grade is C.")Else TextWindow.WriteLine("The student’s grade is D.")EndIf n = n + 1EndWhile