TIK-20 Computer and Information Science April 3, 2009 1TIK20 - West Hill C.I. - Spring 2009.

Slides:



Advertisements
Similar presentations
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Advertisements

Microsoft Visual Basic: Reloaded Chapter Six Repeating Program Instructions.
Executes a statement or statements for a number of times – iteration. Syntax for(initialize; test; increment) { // statements to be executed } Initial.
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.
This presentation contains the following: -the availability and need menu options -the add option Mark Smith.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
CIS101 Introduction to Computing Week 12 Spring 2004.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
JavaScript Switch Statement. Switch JavaScript Switch Statement If you have a lot of conditions, you can use a switch statement instead of an if…elseif…
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 6 – Car Payment Calculator Application: Introducing.
Real World Programming BBrewer Fall Programming - Bellwork 1.Log on 2.Go to edmodo 3.Open & Save Vocabulary Graphic Organizer and Analaysis Document.
Loops Doing the same thing over and over and over and over and over and over…
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Chapter 12: How Long Can This Go On?
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
1 Loops. 2 Topics The while Loop Program Versatility Sentinel Values and Priming Reads Checking User Input Using a while Loop Counter-Controlled (Definite)
Scratch Programming Lesson 4 Question asking and answering.
Copyright ©2005  Department of Computer & Information Science Introducing Dialogue Windows.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
JavaScript Adding active content to websites. Goals Understand structure of JavaScript Understand rules of coding Add active content to WebPages Add functions.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 4 Looping.
Logic Our programs will have to make decisions in terms of what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if.
Access Forms and Queries. Entering Data in Your Table  You can add data to your table in Datasheet view, by typing in the columns and rows.  This.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 1 Simple Python Programs Using Print, Variables, Input.
Variety of JavaScript Examples Please use speaker notes for additional information!
Input & Output Functions JavaScript is special from other languages because it can accept input and produce output on the basis of that input in the same.
1 A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 4 JavaScript and.
JavaScript, Fourth Edition
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Access 2010 by Robert Grauer, Keith Mast, and Mary Anne.
JavaScript Challenges Answers for challenges
Lesson 1. Security At the menu bar at the top you will see the word Tools. Click your mouse on Tools scroll down to Macro. Move the Mouse over and down.
Controlling Program Flow with Looping Structures
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
An Overview of the Energy Reduction Calculator.  Calculates reduction in emissions for a facility Emissions computed are Carbon Dioxide, Sulfur Dioxide,
Access Queries and Forms. Adding a New Field  To insert a field after you have saved your table, open Access, and open the table  It is easier to add.
Solving Problems with Repetition Version 1.0. Objectives At the end of this topic, students should be able to: Correctly use a while statement in a C#
CNIT 133 Interactive Web Pags – JavaScript and AJAX Popup Boxes.
General Condition Loop A general condition loop just loops while some condition remains true. Note that the body of the loop should (eventually) change.
Learning Javascript From Mr Saem
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #003 (February 14, 2015)
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 6 Controlling Program Flow with Looping Structures.
CHAPTER 10 JAVA SCRIPT.
Tutorial 10 – Class Average Application Introducing the Do…Loop While and Do…Loop Until Repetition Statements Outline Test-Driving the Class Average.
Scratch – Simple Programming
Topics Introduction to Repetition Structures
CHAPTER 4 CLIENT SIDE SCRIPTING PART 2 OF 3
While Loops Chapter 3.
Predefined Dialog Boxes
When I want to execute the subroutine I just give the command Write()
Selection CIS 40 – Introduction to Programming in Python
Please use speaker notes for additional information!
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
We are starting to program with JavaScript
T. Jumana Abu Shmais – AOU - Riyadh
Introduction to TouchDevelop
CS105 Introduction to Computer Concepts
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
JavaScript.
Programming Concepts and Database
Basic Lessons 5 & 6 Mr. Kalmes.
Loops.
Web Programming– UFCFB Lecture 13
Basic Mr. Husch.
CS105 Introduction to Computer Concepts JavaScript
Presentation transcript:

TIK-20 Computer and Information Science April 3, TIK20 - West Hill C.I. - Spring 2009

Lesson 7a: Conditional Loops Homework 1.A program accepts the price of a new car, trade- in-allowance, and down payment, and then tells how much is owing on the car. The program continues to ask the user if he/she would like to continue entering values (with a confirm dialogue box--see script examples for an explanation of what they are and how they work) and continues to perform the calculations if the user clicks OK, but exits if the person clicks CANCEL. 2TIK20 - West Hill C.I. - Spring 2009

Lesson 7a: Conditional Loops Homework Write a program segment containing a loop for a program that accepts the number of words in a classified ad as input and calculates the price of the ad based on the following criteria (using selection statements): The output should be in the following format: The West Hill Classifieds The cost of your classified ad is $__________. The loop should continue to accept values until the user clicks CANCEL at the confirm dialogue box prompt. TIK20 - West Hill C.I. - Spring Number of WordsPrice 1 to 50 words$ to 100 words$ to 200 words$75.00

Today’s Agenda 1.>, =,<=,==,!= 2.for, while 3.IPO and Lesson 7a Homework 4.DO (1) and (2) at your workstations 5.Show Mr. Robinson or Ms. Jansen that your programs are working before you leave. 4TIK20 - West Hill C.I. - Spring 2009

A=1; B=1; C=2; D=2; E=3 Tell me if the following are true or false A > B || C >= D true or false B < C && C != D true or false A <= B || B == E true or false 5TIK20 - West Hill C.I. - Spring 2009

For loops Recall for loops from last class… for (i = 0; i < 5; i++){ document.write(i + “ ”) } 6TIK20 - West Hill C.I. - Spring 2009

Now the while loop Easier to use than the for loop is the while loop. A while loop doesn't initialize or increment any fields automatically as part of the command. It just tests a condition and executes the loop for as long as the condition remains true. 7TIK20 - West Hill C.I. - Spring 2009

Let's begin by looking at a simple while statement: x = 0 // initialize before the loop while (x<10) { document.write(x + " ") x++; // increment the variable inside loop } TIK20 - West Hill C.I. - Spring 20098

Common errors 9TIK20 - West Hill C.I. - Spring 2009 Forget to do something to the value that is being tested. What’s wrong here? x = 0 // initialize before the loop while (x<10) { document.write(x + " ") }

Do while loop The “test” goes to the bottom of the loop: x = 12 do { document.write(x) x++ } while (x<10) TIK20 - West Hill C.I. - Spring

Do while loop - note In this example the loop will execute once even though the original value of x is greater than that tested for in the while condition. TIK20 - West Hill C.I. - Spring

Back to Lesson 7a Recall an IPO Input: Input from the keyboard Processing: Operations carried out by the computer Output: Variables (storing data) that will be output to the screen 12TIK20 - West Hill C.I. - Spring 2009

Question from Homework A program accepts the price of a new car, trade-in- allowance, and down payment, and then tells how much is owing on the car. The program continues to ask the user if he/she would like to continue entering values (with a confirm dialogue box--see script examples for an explanation of what they are and how they work) and continues to perform the calculations if the user clicks OK, but exits if the person clicks CANCEL. 13TIK20 - West Hill C.I. - Spring 2009

Translate to Javascript response = “” // Cancel button pressed??? while(response != null){ document.write(response) response=prompt("How are you today? ","") } TIK20 - West Hill C.I. - Spring

Lesson 7a: Conditional Loops Homework Write a program segment containing a loop for a program that accepts the number of words in a classified ad as input and calculates the price of the ad based on the following criteria (using selection statements): The output should be in the following format: The West Hill Classifieds The cost of your classified ad is $__________. The loop should continue to accept values until the user clicks CANCEL at the confirm dialogue box prompt. TIK20 - West Hill C.I. - Spring Number of WordsPrice 1 to 50 words$ to 100 words$ to 200 words$75.00