Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Control Structures: continued.

Slides:



Advertisements
Similar presentations
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
Advertisements

Session 5 JavaScript/JScript: Control Structures II Matakuliah: M0114/Web Based Programming Tahun: 2005 Versi: 5.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 4 – C Program Control Outline 4.1Introduction.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
Control Structures: Part 2. Introduction Essentials of Counter-Controlled Repetition For / Next Repetition Structure Examples Using the For / Next Structure.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Control Structure.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Objectives You should be able to describe:
 2007 Pearson Education, Inc. All rights reserved C Program Control.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
 2002 Prentice Hall. All rights reserved. 1 Chapter 3 – Control Structures Outline 3.1 Introduction 3.2 Algorithms 3.3 Pseudocode 3.4Control Structures.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved The switch Multiple-Selection Statement switch.
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
For Repetition Structures (L13) * General Form of the for Statement * Components of a Typical for Header * Pre/Postincrement of the Counter * Stream Manipulator.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 9 - JavaScript: Control Statements II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled.
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (Switch, do-while, break) Outline 4.7The.
Chapter 4 C Program Control. Objectives In this chapter, you will learn: –To be able to use the for and do … while repetition statements. –To understand.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 18 - WMLScript: Control Structures II Outline 18.1 Introduction 18.2 Essentials of Counter-Controlled.
Programming in Java Unit 4. Learning outcome:  LO2: Be able to design Java solutions  LO3: Be able to implement Java solutions Assessment criteria:
University of Palestine software engineering department Introduction to data structures Control Statements: Part 1 instructor: Tasneem Darwish.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
Java™ How to Program, Early Objects Version, 8/e © by Pearson Education, Inc. All Rights Reserved.
Sections 5.1 – 5.4 © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1 Introduction 5.2 Essentials of Counter-Controlled.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
Essentials of Counter-Controlled Repetition Counter-controlled repetition requires: Control variable (loop counter) Initial value of the control variable.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
5.1 Introduction Problem Solving –Requires understanding of: Building blocks Program-construction principles BZUPAGES.COM.
Lecture 7: Menus and getting input. switch Multiple-selection Statement switch Useful when a variable or expression is tested for all the values it can.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
 2002 Prentice Hall. All rights reserved. 1 Chapter 5 – Control Structures: Part 2 Outline 5.1Introduction 5.2 Essentials of Counter-Controlled Repetition.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 4: Control Structures (Part 2) Xiang Lian The University of Texas – Pan American Edinburg, TX
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 9 - JavaScript: Control Structures II Outline 9.1 Introduction 9.2 Essentials of Counter-Controlled.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 9 - JavaScript: Control Statements II
Chapter 5- Control Structures: Part 2
Control Structures: Part 2
Chapter 15 - JavaScript/JScript: Control Structures II
JavaScript: Control Statements.
JavaScript: Control Statements (II)
Chapter 9 - JavaScript: Control Structures II
Chapter 4 - Program Control
Chapter 6 Control Statements: Part 2
Presentation transcript:

Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Control Structures: continued

Objectives In this lesson, you will learn: – To be able to use the for and do … while repetition statements to execute statements in a program repeatedly. – To understand multiple selection using the switch selection statement. – To be able to use the break and continue program-control statements. – To be able to use the logical operators.

Essentials of Counter-Controlled Repetition Counter-controlled repetition – Name of a control – Initial value – Increment or decrement – Final value

for Repetition Statement for repetition statement – Handles all the details of counter-controlled repetition – Contains the counter declaration – Contains the explicit incrementing expression – Contains the loop stopping/continuation condition (final value)

Outline ForCounter.html (1 of 1)

for Repetition Statement for (var counter =1; counter <=7; ++counter ) Initial value of control variable Increment of control variable Control variable name Final value of control variable for which the condition is true for keyword Loop-continuation condition Fig. 9.3 for statement header components.

for Loop : Compound Interest Example The code that will create a table containing showing the total amount of money in each of the next 10 years assuming that – annual interest is 5% – no withdrawals have occurred – Starting principal is $1,000 Amount Year = Principal (1+Interest) Year

Outline Interest.html (1 of 2)

Outline Interest.html (2 of 2)

In-class exercise Modify the previous JavaScript code in following fashion – Instead of fixed principal amount, interest rate and number of years it should prompt user for those three values an create the table accordingly

switch Multiple-Selection Statement Controlling expression – typically a variable with multiple possible values Case labels – Typically, each case label will correspond to one of the possible values of the controlling expression Case block of statements – No brackets needed – Always finish with a break statement Default case – Optional, specifies what to do if the value of control expression is something else than specified in case labels

switch Multiple-Selection Statement case a a action(s) true false... break case b action(s) break false case z z action(s) break default action(s) true case b

Outline SwitchTest.html (1 of 3)

Outline SwitchTest.html (2 of 3) Note that there are NO “{“ and “}” brackets at the beginning of each case block

Outline SwitchTest.html (3 of 3)

In-class exercise 2 Modify the previous JavaScript code in following fashion – Add one more choice for the user to choose from 4 (squared): it should display an unordered list where items are marked by squares instead of bullets. The type declaration is:

Logical Operators More logical operators – Logical AND ( && ) – Logical OR ( || ) – Logical NOT ( ! )

Logical Operators

Outline LogicalOperators.html (1 of 2)

Outline LogicalOperators.html (2 of 2)

Summary of Structured Programming Flowcharts – Reveal the structured nature of programs Single-entry/single-exit control structures – Only one way to enter and one way to exit each control structure Control structure stacking – The exit point of one control structure is connected to the entry point of the next control structure

Recommended Rules of Structured Programming:

Description of “Action” may get more specific

Action being replaced by control structure

Unstructured Flowchart Such outcome should never occur if recommended rules are followed