Đang chuẩn bị liên kết để tải về tài liệu:
Lecture Java: Chapter 6

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Lecture Java: Chapter 6 focuses on the switch statement, the conditional operator, the do loop, the for loop, drawing with the aid of conditionals and loops, dialog boxes. | Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus 1 More Conditionals and Loops Now we can fill in some additional details regarding Java conditional and repetition statements Chapter 6 focuses on: the switch statement the conditional operator the do loop the for loop drawing with the aid of conditionals and loops dialog boxes Copyright © 2012 Pearson Education, Inc. Outline The switch Statement The Conditional Operator The do Statement The for Statement Drawing with Loops and Conditionals Dialog Boxes Copyright © 2012 Pearson Education, Inc. The switch Statement The switch statement provides another way to decide which statement to execute next The switch statement evaluates an expression, then attempts to match the result to one of several possible cases Each case contains a value and a list of statements The flow of control transfers to statement associated . | Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus 1 More Conditionals and Loops Now we can fill in some additional details regarding Java conditional and repetition statements Chapter 6 focuses on: the switch statement the conditional operator the do loop the for loop drawing with the aid of conditionals and loops dialog boxes Copyright © 2012 Pearson Education, Inc. Outline The switch Statement The Conditional Operator The do Statement The for Statement Drawing with Loops and Conditionals Dialog Boxes Copyright © 2012 Pearson Education, Inc. The switch Statement The switch statement provides another way to decide which statement to execute next The switch statement evaluates an expression, then attempts to match the result to one of several possible cases Each case contains a value and a list of statements The flow of control transfers to statement associated with the first case value that matches Copyright © 2012 Pearson Education, Inc. The switch Statement The general syntax of a switch statement is: switch ( expression ) { case value1 : statement-list1 case value2 : statement-list2 case value3 : statement-list3 case . } switch and case are reserved words If expression matches value2, control jumps to here Copyright © 2012 Pearson Education, Inc. The switch Statement Often a break statement is used as the last statement in each case's statement list A break statement causes control to transfer to the end of the switch statement If a break statement is not used, the flow of control will continue into the next case Sometimes this may be appropriate, but often we want to execute only the statements associated with one case Copyright © 2012 Pearson Education, Inc. The switch Statement switch (option) { case 'A': aCount++; break; case 'B': bCount++; break; case 'C': cCount++; break; } An example of a switch statement: Copyright © 2012 Pearson