Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.

Slides:



Advertisements
Similar presentations
Chapter 4: Control Structures I (Selection)
Advertisements

Introduction to C Programming
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
While loops.
How SAS implements structured programming constructs
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
CS0004: Introduction to Programming Repetition – Do Loops.
 Control structures  Algorithm & flowchart  If statements  While statements.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
16/27/ :53 PM6/27/ :53 PM6/27/ :53 PMLogic Control Structures Arithmetic Expressions Used to do arithmetic. Operations consist of +,
Copyright © Texas Education Agency, Computer Programming For Loops.
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
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.
Fundamentals of Python: From First Programs Through Data Structures
Summer Computing Workshop. Session 4 Loops  At the heart of their functionality, loops enable blocks of code to be executed more than once  Loops represent.
Fundamentals of Python: First Programs
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Programming & Scratch. Programming Learning to program is ultimately about learning to think logically and to approach problems methodically. The building.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
PL/SQL Loops. Building Logical Conditions All logical conditions must yield a boolean condition. You can build a simple Boolean condition by combining.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Summer Computing Workshop. Introduction  Boolean Expressions – In programming, a Boolean expression is an expression that is either true or false. In.
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
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.
Statement Level Flow of Control Iteration Structures Copyright © by Curt Hill.
JavaScript, Fourth Edition
MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 13 Conditional.
Summer Computing Workshop. Session 3 Conditional Branching  Conditional branching is used to alter the normal flow of execution depending on the value.
CSCI 161 Lecture 7 Martin van Bommel. Control Statements Statements that affect the sequence of execution of other statements Normal is sequential May.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
More Python!. Lists, Variables with more than one value Variables can point to more than one value at a time. The simplest way to do this is with a List.
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University ©2011 Pearson Prentice Hall ISBN Chapter 13 Conditional.
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.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
9. ITERATIONS AND LOOP STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Loops and Arrays Chapter 19 and Material Adapted from Fluency Text book.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
IST 210: PHP Logic IST 210: Organization of Data IST2101.
FOP: While Loops.
Python: Control Structures
CiS 260: App Dev I Chapter 4: Control Structures II.
Chapter 6: Conditional Statements and Loops
Expressions and Control Flow in JavaScript
JavaScript: Control Statements.
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Chapter 8 JavaScript: Control Statements, Part 2
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
3 Control Statements:.
Selection Statements.
Computer Science Core Concepts
ICT Programming Lesson 3:
Repetition Statements (Loops) - 2
PROGRAM FLOWCHART Iteration Statements.
REPETITION Why Repetition?
Presentation transcript:

Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop

Loops Session SA-3

Loops At the heart of their functionality, loops enable blocks of code to be executed more than once. Loops represent a simple concept that can be used to create extremely dynamic and flexible programs. There are several different constructs in programming for implementing loops. Some loops simply count the number of times a block of code is executed and the loop will be exited once a pre-determine number of reiterations have been reached (do ‘this same thing’ 10 times). If needed a variable can be used as an index for the loop. The index is a counter for the current count of the execution of the loop. Loops can be made to continue until a specific condition is obtained. Loops can be made to repeat execution for each item in a list. Loops can be made to loop indefinitely.

The Loop Block For Range loop In the App Inventor, the simplest type of loop is the for range loop block. It closely resembles the “for” loop found in other programming languages. This loop executes 10 times. The variable named ‘i’ will be incremented by the step value with each iteration of the loop. In this case, it is increment by 1. The variable ‘i’ will equal 1 the first time through the loop, 2 the second time and so on. The Label1.Text is set to the value of ‘i’ each time the loop is executed. With each time through the loop, ‘i’ is compared to the end number (10). Once ‘i’ is greater than 10 the loop will exit. The for range loop is dependant on an implied Boolean expression comparing the named variable i to the start and end values set for the loop. The for range loop requires a start value, an end value, a step value, and a named variable whose scope is restricted to inside the for range loop block. Unlike normal variable whose scope is anywhere in the program.

The While Loop The while loop, as the name implies, keeps repeating while a given Boolean expression is true. A Boolean expression evaluates to either True or False. It is identical to the while loop found in other programming languages. The example above loops 10 times (until var1 is great than 10). With each iteration, var1 is increment by 1. While loops are perfect when combined with user input. This allows the user to interact with the program indefinitely; loops such as these are found in almost every program in some form. Boolean Expression

Infinite Loops In some cases, a loop must continue repeating the entire time the program is running. When this is required an infinite loop is often used. Like the while loop, the infinite loop is commonly used in conjunction with user input. One must be careful when working with loops, infinite loops can cause ‘software to hang’ or cause the system to become very sluggish.

Boolean Expressions Logic Operators The App Inventor provides for several implementations of Boolean expression shown below. The are found under the Built-In tab in the Block Editor in the Math and Logic drawers. A Boolean variable can be either or. You can negate them, or them or and them. You can also compare them The comparison operator can be either =,, not =, =. The operands in these blocks can be a variable with a value of either True or False or the can be a Boolean Expressions. But no matter how you combine them, Boolean expressions evaluate to either True or False.

Project SA_2 Conditional Branching, Boolean Expressions, Loops Create an app where a label starts at 0 and is increased by 1 every time you click a button. Have the ball only move when the labeled number is either even or odd.

Day 2 Questions Conditional Branching, Boolean Expressions, Loops 1.What part of an If/Else control structure determines which sequence of blocks is executed? 2.The expression in the predicate part of an If/Else structure evaluates to a _____ or _____ value. 3.What part of the If/Else structure would execute if the predicate value was true? 4.If a certain block or number of blocks needed to be executed several times, what control structure would you use? 5.If a loop executes 5 times and there was a block inside that incremented the variable varCount by 3 each time, assuming the variable has an initial value of 0, what is the ending value of varCount? 6.The expression in the predicate part of an If/Else structure evaluates to what type of value? 7.If the condition of a while loop was set to “true” how many times would this loop execute?

Day 2 Answer Key Conditional Branching, Boolean Expressions, Loops 1.What part of an If/Else control structure determines which sequence of blocks is executed? The predicate (the Boolean expression attached to the test socket of the if blocks). 2.The expression in the predicate part of an If/Else structure evaluates to a _true_ or _false_ value. 3.What part of the If/Else structure would execute if the predicate value was true? consequent (internal) section (the ‘then-do’ block) 4.If a certain block or number of blocks needed to be executed several times, what control structure would you use? a loop block (for range loop, while loop) 5.If a loop executes 5 times and there was a block inside that incremented the variable varCount by 3 each time, assuming the variable has an initial value of 0, what is the ending value of varCount? 15 6.The expression in the predicate part of an If/Else structure evaluates to what type of value? A Boolean value (true or false) 7.If the condition of a while loop was set to “true” how many times would this loop execute? an infinite number of times