kelompok 8 pbw

28
Kelompok 8 Java Script : Control Statement II Oleh: Kukuh I. 5108100122 Brian M. 5108100156 Yodiar Hellian 5108100165

Upload: guestdf5a09

Post on 22-May-2015

237 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Kelompok 8 Pbw

Kelompok 8 Java Script : Control Statement II

Kelompok 8 Java Script : Control Statement II

Oleh:Kukuh I. 5108100122Brian M. 5108100156Yodiar Hellian 5108100165

Page 2: Kelompok 8 Pbw

Chapter 8 - JavaScript: Control Statements IIChapter 8 - JavaScript: Control Statements II

1. Introduction2. Essentials of Counter-Controlled Repetition3. For Repetition Statement4. Examples Using the for Statement5. Switch Multiple-Selection Statement6. Do…while Repetition Statement7. Break and continue Statements8. Labeled break and continue Statements9. Logical Operators

Page 3: Kelompok 8 Pbw

1. Introduction

• Continuation of Chapter 8– Theory and principles of structured programming

Page 4: Kelompok 8 Pbw

2. Essentials of Counter-Controlled Repetition

• Counter-controlled repetition– Name of a control– Initial value– Increment or decrement– Final value

Page 5: Kelompok 8 Pbw

While Counter.html

Page 6: Kelompok 8 Pbw

3. for Repetition Statement

• for repetition statement– Handles all the details of counter-controlled

repetition– for structure header

• The first line

Page 7: Kelompok 8 Pbw

3. for Repetition Statement

for ( var counter=1 ; counter<=7 ; ++counter )

Initial value of control variable Increment control variable

Control variable name Final value of control variable for which the condition is true

for keyword

Loop-continuation condition

Page 8: Kelompok 8 Pbw

3. for Repetition Statement

counter <= 7

document.writeln( "<p style=\"font-size: " + counter + "ex\">XHTML font size " + counter + "ex</p>" );

true

false

var counter = 1

++counter

Establish initial valueof control variable.

Determine if final value of control variable has been reached.

Body of loop (this may be many statements)

Increment the control variable.

Fig. 9.4 for repetition structure flowchart.

Page 9: Kelompok 8 Pbw

For Counter.html

Page 10: Kelompok 8 Pbw

4. Examples Using the for Statement

• Summation with for• Compound interest calculation with for loop

– Math object• Method pow• Method round

Page 11: Kelompok 8 Pbw

Sum.html

Page 12: Kelompok 8 Pbw

Interest.html

Page 13: Kelompok 8 Pbw

5. switch Multiple-Selection Statement

• Controlling expression• Case labels• Default case

Page 14: Kelompok 8 Pbw

SwitchTest.html

Page 15: Kelompok 8 Pbw

5. switch Multiple-Selection Statement

case a case a action(s)true

false

.

.

.

break

case b action(s) break

false

false

case z case z action(s) break

default action(s)

true

true

case b

Page 16: Kelompok 8 Pbw

6. do…while Repetition Statement

• Similar to the while statement• Tests the loop continuation condition after the

loop body executes• Loop body always executes at least once

Page 17: Kelompok 8 Pbw

6. do…while Repetition Structure

conditiontrue

action(s)

false

Fig. 9.10 do…while repetition statement flowchart.

Page 18: Kelompok 8 Pbw

DoWhile.html

Page 19: Kelompok 8 Pbw

7. break and continue Statements

• break

– Immediate exit from the structure– Used to escape early from a loop– Skip the remainder of a switch statement

• continue

– Skips the remaining statements in the body of the structure

– Proceeds with the next iteration of the loop

Page 20: Kelompok 8 Pbw

BreakTest.html

Page 21: Kelompok 8 Pbw

ContinueTest.html

Page 22: Kelompok 8 Pbw

8. Labeled break and continue Statements

• Labeled break statement– Break out of a nested set of structures– Immediate exit from that structure and enclosing

repetition structures– Execution resumes with first statement after enclosing

labeled statement• Labeled continue statement

– Skips the remaining statements in structure’s body and enclosing repetition structures

– Proceeds with next iteration of enclosing labeled repetition structure

– Loop-continuation test evaluates immediately after the continue statement executes

Page 23: Kelompok 8 Pbw

BreakLabelTest.html

Page 24: Kelompok 8 Pbw

ContinueLabelTest.html

Page 25: Kelompok 8 Pbw

9. Logical Operators

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

Page 26: Kelompok 8 Pbw

9 Logical Operators

expression1 expression2 expression1 && expression2

false false false false true false true false false true true true

Page 27: Kelompok 8 Pbw

9. Logical Operatorsexpression1 expression2 expression1 ||

expression2 false false false false true true true false true true true true

expression !expression false true true false

Page 28: Kelompok 8 Pbw

LogicalOperators.html