Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

2 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.

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

4 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)

5 Outline ForCounter.html (1 of 1)

6

7 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.

8 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

9 Outline Interest.html (1 of 2)

10 Outline Interest.html (2 of 2)

11 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

12 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

13 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

14 Outline SwitchTest.html (1 of 3)

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

16 Outline SwitchTest.html (3 of 3)

17

18

19 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:

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

21 Logical Operators

22

23 Outline LogicalOperators.html (1 of 2)

24 Outline LogicalOperators.html (2 of 2)

25

26 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

27 Recommended Rules of Structured Programming:

28 Description of “Action” may get more specific

29 Action being replaced by control structure

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


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

Similar presentations


Ads by Google