Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

Microsoft® Small Basic
How SAS implements structured programming constructs
Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
Microsoft® Small Basic
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Programming with Microsoft Visual Basic th Edition
CS0004: Introduction to Programming Repetition – Do Loops.
Computer Science 1620 Loops.
CS 106 Introduction to Computer Science I 02 / 11 / 2008 Instructor: Michael Eckmann.
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
Microsoft® Small Basic
COMP 1001: Introduction to Computers for Arts and Social Sciences Programming in Scratch Monday, May 16, 2011.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Engineering 1020 Introduction to Programming Peter King Winter 2010.
Microsoft® Small Basic
Bug Session Four. Session description Objectives Session activities summary Resources Prior knowledge of sequencing instructions using Bug Bug website.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
A Simple Quiz: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009, added Part 2 July 2011.
By Chad Blankenbeker.  The for-loop is best used when you know how many times it is going to be looped  So if you know you want it to only loop 10 times,
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Microsoft® Small Basic Collision Detection Estimated time to complete this lesson: 1 hour.
 There are times when you will want blocks to repeat. Instead of duplicating blocks and ending up with a long script that might be confusing, there.
Microsoft® Small Basic
Introduction to Loops For Loops. Motivation for Using Loops So far, everything we’ve done in MATLAB, you could probably do by hand: Mathematical operations.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
CW-V1 SDD 0901 Principals of Software Design and Development Loops Starter: Water JugsWater Jugs.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 13 Conditional.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
ITEC 109 Lecture 11 While loops. while loops Review Choices –1 st –2 nd to ?th –Last What happens if you only use ifs? Can you have just an else by itself?
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Chapter 7 Problem Solving with Loops
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
Visual Basic.NET BASICS Lesson 11 List Boxes, For Next Loops, and Label Settings.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Objective of the lesson Use Blockly to make a dice for Snakes and Ladders All of you will: – Make an image which displays when you press a button Most.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC530 Data Structures - LOOP 7/9/20161.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
FOP: While Loops.
Special Triangles Review
Week 1, Day 3 Lazy Coding 29 June 2016.
Whatcha doin'? Aims: To start using Python. To understand loops.
While Loops in Python.
Microsoft® Small Basic
Starter Write a program that asks the user if it is raining today.
Iterations Programming Condition Controlled Loops (WHILE Loop)
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
elppa legoog erawdrah erawtfos margorp Cisab llams Apple Google
Selection CIS 40 – Introduction to Programming in Python
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Chapter (3) - Looping Questions.
Introduction to TouchDevelop
CIS 16 Application Development Programming with Visual Basic
Design and Implementation
Flowcharts and Pseudo Code
Class 4: Repetition Pretest Posttest Counting Flowchart these!
Instructor: Craig Duckett
True / False Variables.
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
GCSE Computing.
Presentation transcript:

Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours

Loops in Small Basic Programs So, let’s explore some loop statements… 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.

Loops in Small Basic Programs Click the button on the Toolbar. 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.

Loops in Small Basic Programs Let’s use this concept to print the multiplication table for the number 5.

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:

If you don’t know the loop count before you write a program, you can create a While loop instead of a For loop. Loops in Small Basic Programs Let’s write the following program to demonstrate the While 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 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. 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.

Experts  Use the construct shapes to work out the constructs  Write the code comments  Code the program to make ONE run through  When it is working add a loop to ASK the user if they would like to go again Create a program to get a number and then write out the times table for that number. Use a For loop to count through the times table Once running use a while loop to repeat the program

Show What You Know Open the Fortune teller program from last lesson. Can you encase the code in a loop so the program asks the user if they would like another turn. A While loop would be ideal  Experiment with a game of your own  You could ask the user questions and choose a reply according to their answers.  You could take them on a fantasy journey based on their choice of direction N, S, E or West  You could create a quiz