Starter Write a program that asks the user if it is raining today.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Microsoft® Small Basic
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Chapter 6: The Repetition Structure
Programming with Microsoft Visual Basic th Edition
True BASIC Ch. 6 Practice Questions. What is the output? PRINT X LET X = -1 PRINT X FOR X = 4 TO 5 STEP 2 PRINT X NEXT X PRINT X END.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
Adding Automated Functionality to Office Applications.
Microsoft® Small Basic
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Chapter 12: How Long Can This Go On?
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
Bug Session Four. Session description Objectives Session activities summary Resources Prior knowledge of sequencing instructions using Bug Bug website.
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
Tutorial 6 The Repetition Structure
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Microsoft® Small Basic
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
Algorithms and Pseudocode
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
Learning Javascript From Mr Saem
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.
Visual Basic.NET Windows Programming
CSC111 Quick Revision.
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
Repetition Structures Chapter 9
Lesson 4 - Challenges.
Chapter 5: Control Structure
JavaScript Syntax and Semantics
3rd prep. – 2nd Term MOE Book Questions.
Microsoft Excel 2003 Illustrated Complete
3rd prep. – 2nd Term MOE Book Questions.
Chapter 2 Visual Basic Interface
Control Structure Senior Lecturer
Control Structure Senior Lecturer
elppa legoog erawdrah erawtfos margorp Cisab llams Apple Google
File Handling Programming Guides.
Microsoft® Small Basic
Exploring Microsoft Excel
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Microsoft® Small Basic
Chapter (3) - Looping Questions.
T. Jumana Abu Shmais – AOU - Riyadh
Introduction to TouchDevelop
CIS 16 Application Development Programming with Visual Basic
Introduction to Problem Solving and Control Statements
Text / Serial / Sequential Files
3.1 Iteration Loops For … To … Next 18/01/2019.
Nested Loops & The Step Parameter
ICT Gaming Lesson 3.
Flowcharts and Pseudo Code
Programming In Lesson 4.
Topics Introduction to Repetition Structures
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Lesson 4.
3.2 Working with Data Scope of variables 29/07/2019.
Primary School Computing
Intro to Programming (in JavaScript)
Presentation transcript:

Starter Write a program that asks the user if it is raining today. Statements, Properties, and Operations Starter Write a program that asks the user if it is raining today. Use IF, Else to display a message to the user that tells them they need an umbrella or not depending on if it is raining Top-tip – look back at previous code If your variable is text it will need to be in “” speech marks

How did you do?

IF, Else, Elseif, Then & Endif Wednesday, September 19, 2018 Homework - Last Week IF, Else, Elseif, Then & Endif Hand in for marking

Write your homework in your planner – it’s due next week Wednesday, September 19, 2018 Homework - This Week Write your homework in your planner – it’s due next week Loops

Microsoft® Small Basic Loops – For or While Estimated time to complete this lesson: 1 hour

Conditions In this lesson, you will learn how to: Be able to write programs that repeat instructions until a specific event occurs.

Loops in Small Basic Programs You can use a loop to instruct the computer to run one or more statements more than once. You can use a For loop if you know how many times you want the computer to repeat the instructions. You can use a While loop if you want the program to repeat the instructions until a specific condition is true. So, let’s explore some loop statements…

Loops in Small Basic Programs 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. Code: For a = 1 to 10 TextWindow.WriteLine(a) EndFor Click the button on the Toolbar. In this example, the variable contains a value that increases by 1 every time that the loop runs.

Loops in Small Basic Programs Let’s use this concept to print the multiplication table for the number 5. Commas mean this is seen as text (this is called a “string”) and written to screen Variables Variable – holds the value of the table to be written Variable a – holds the values which change each time a line is written from 1 to 10 * Is used to complete the multiplication not an X

Loops in Small Basic Programs Let’s use this concept to print the multiplication table for the number 5. output 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” variables Code: TextWindow.WriteLine("Multiplication Table") number = 5 For a = 1 to 10 TextWindow.WriteLine(a + " x " + number + " = " + a * number) EndFor

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: 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 = 5 For a = 1 to 10 Step 2 TextWindow.WriteLine(a + " x " + number + " = " + a * number) EndFor

Loops in Small Basic Programs If you don’t know the loop count before you write a program, you can create a While loop instead of a For loop. 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. Let’s write the following program to demonstrate the While loop: 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 = 10 While (a <= 100) TextWindow.WriteLine(a) a = a +10 EndWhile

Let’s Summarize… Congratulations! Now you know how to: Write programs that repeat instructions until a specific event occurs.

Show What You Know Now add some comments to explain what each line of this code is doing. Look at your previous code and use that to help you. Solution: to add a comment to a line of code type in an apostrophe and write your comment – it should write in green.

Consolidate – Exit ticket Wednesday, September 19, 2018 Consolidate – Exit ticket WWW - One thing you learned today? Or One thing you enjoyed today? EBI – One thing you could do better One thing you will need help with next lesson?