9781111530532 ppt ch04
-
Upload
terry-yoast -
Category
Education
-
view
521 -
download
3
Transcript of 9781111530532 ppt ch04
![Page 1: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/1.jpg)
Java Programming: From Problem Analysis to Program Design, 5e
Chapter 4Control Structures I: Selection
![Page 2: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/2.jpg)
2Java Programming: From Problem Analysis to Program Design, 5e
Chapter Objectives
• Learn about control structures
• Examine relational and logical operators
• Explore how to form and evaluate logical (Boolean) expressions
• Learn how to use the selection control structures if, if…else, and switch in a program
![Page 3: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/3.jpg)
3Java Programming: From Problem Analysis to Program Design, 5e
Control Structures
• Three methods of processing a program– In sequence– Branching– Looping
• Branch: altering the flow of program execution by making a selection or choice
• Loop: altering the flow of program execution by repetition of statement(s)
![Page 4: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/4.jpg)
4Java Programming: From Problem Analysis to Program Design, 5e
Flow of Execution
![Page 5: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/5.jpg)
5Java Programming: From Problem Analysis to Program Design, 5e
Relational Operators
• Relational operator– Allows you to make comparisons in a program– Binary operator
• Condition is represented by a logical expression in Java
• Logical expression: expression that has a value of either true or false
![Page 6: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/6.jpg)
6Java Programming: From Problem Analysis to Program Design, 5e
Relational Operators in Java
![Page 7: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/7.jpg)
7Java Programming: From Problem Analysis to Program Design, 5e
Relational Operators and Primitive Data Types
• Can be used with integral and floating-point data types
• Can be used with the char data type
• Unicode collating sequence
![Page 8: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/8.jpg)
8Java Programming: From Problem Analysis to Program Design, 5e
![Page 9: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/9.jpg)
9Java Programming: From Problem Analysis to Program Design, 5e
![Page 10: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/10.jpg)
10Java Programming: From Problem Analysis to Program Design, 5e
Relational Operators and the Unicode Collating Sequence
![Page 11: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/11.jpg)
11Java Programming: From Problem Analysis to Program Design, 5e
Logical (Boolean) Operators
![Page 12: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/12.jpg)
12Java Programming: From Problem Analysis to Program Design, 5e
Logical (Boolean) Operators (continued)
![Page 13: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/13.jpg)
13Java Programming: From Problem Analysis to Program Design, 5e
Logical (Boolean) Operators (continued)
![Page 14: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/14.jpg)
14Java Programming: From Problem Analysis to Program Design, 5e
Logical (Boolean) Operators (continued)
![Page 15: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/15.jpg)
15Java Programming: From Problem Analysis to Program Design, 5e
Precedence of Operators
![Page 16: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/16.jpg)
16Java Programming: From Problem Analysis to Program Design, 5e
Precedence of Operators (continued)
![Page 17: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/17.jpg)
17Java Programming: From Problem Analysis to Program Design, 5e
![Page 18: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/18.jpg)
18Java Programming: From Problem Analysis to Program Design, 5e
![Page 19: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/19.jpg)
19Java Programming: From Problem Analysis to Program Design, 5e
![Page 20: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/20.jpg)
20Java Programming: From Problem Analysis to Program Design, 5e
Selection
• One-way selection
• Two-way selection
• Compound (block of) statements
• Multiple selections (nested if)
• Conditional operator• switch structures
![Page 21: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/21.jpg)
21Java Programming: From Problem Analysis to Program Design, 5e
One-Way Selection
• Syntaxif (expression)
statement
• Expression referred to as decision maker
• Statement referred to as action statement
![Page 22: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/22.jpg)
One-Way Selection (continued)
Java Programming: From Problem Analysis to Program Design, 5e 22
![Page 23: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/23.jpg)
23Java Programming: From Problem Analysis to Program Design, 5e
Example 4-7
//Program to determine the absolute value of an integer
import javax.swing.JOptionPane;
public class AbsoluteValue
{
public static void main(String[] args)
{
int number;
int temp;
String numString;
numString =
JOptionPane.showInputDialog
("Enter an integer:"); //Line 1
number = Integer.parseInt(numString); //Line 2
temp = number; //Line 3
One-Way Selection (continued)
![Page 24: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/24.jpg)
24Java Programming: From Problem Analysis to Program Design, 5e
if (number < 0) //Line 4 number = -number; //Line 5
JOptionPane.showMessageDialog(null, "The absolute value of " + temp + " is " + number, "Absolute Value", JOptionPane.INFORMATION_MESSAGE); //Line 6 System.exit(0); }
One-Way Selection (continued)
![Page 25: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/25.jpg)
25Java Programming: From Problem Analysis to Program Design, 5e
if (number < 0) //Line 4 number = -number; //Line 5
JOptionPane.showMessageDialog(null, "The absolute value of " + temp + " is " + number, "Absolute Value", JOptionPane.INFORMATION_MESSAGE); //Line 6 System.exit(0); }
![Page 26: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/26.jpg)
26Java Programming: From Problem Analysis to Program Design, 5e
Two-Way Selection
• Syntax
if (expression)
statement1
else
statement2• else statement must be paired with an if
![Page 27: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/27.jpg)
27Java Programming: From Problem Analysis to Program Design, 5e
Two-Way Selection (continued)
![Page 28: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/28.jpg)
28Java Programming: From Problem Analysis to Program Design, 5e
Two-Way Selection (continued)
Example 4-10
if (hours > 40.0) wages = 40.0 * rate + 1.5 * rate * (hours - 40.0); else wages = hours * rate;
![Page 29: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/29.jpg)
29Java Programming: From Problem Analysis to Program Design, 5e
Example 4-11
if (hours > 40.0); //Line 1 wages = 40.0 * rate + 1.5 * rate * (hours - 40.0); //Line 2else //Line 3 wages = hours * rate; //Line 4
• Because a semicolon follows the closing parenthesis of the if statement (Line 1), the else statement stands alone • The semicolon at the end of the if statement (see Line 1) ends the if statement, so the statement at Line 2 separates the else clause from the if statement; that is, else is by itself • Since there is no separate else statement in Java, this code
generates a syntax error
Two-Way Selection (continued)
![Page 30: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/30.jpg)
30Java Programming: From Problem Analysis to Program Design, 5e
Two-Way Selection (continued)
![Page 31: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/31.jpg)
31Java Programming: From Problem Analysis to Program Design, 5e
Compound (Block of) Statements• Syntax
![Page 32: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/32.jpg)
32Java Programming: From Problem Analysis to Program Design, 5e
Compound (Block of) Statements (continued)
if (age > 18){ System.out.println("Eligible to vote."); System.out.println("No longer a minor.");} else{ System.out.println("Not eligible to vote."); System.out.println("Still a minor.");}
![Page 33: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/33.jpg)
33Java Programming: From Problem Analysis to Program Design, 5e
Multiple Selection: Nested if
• Syntax
if (expression1)
statement1
else if (expression2)
statement2
else
statement3
• Else associated with most recent incomplete if
• Multiple if statements can be used in place of if…else statements
• May take longer to evaluate
![Page 34: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/34.jpg)
34Java Programming: From Problem Analysis to Program Design, 5e
Multiple Selection: Nested if (continued)
![Page 35: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/35.jpg)
35Java Programming: From Problem Analysis to Program Design, 5e
Multiple Selection: Nested if (continued)
To avoid excessive indentation, the code in Example 4-15 can be rewritten as follows:
![Page 36: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/36.jpg)
36Java Programming: From Problem Analysis to Program Design, 5e
Multiple Selection: Nested if (continued)
![Page 37: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/37.jpg)
37Java Programming: From Problem Analysis to Program Design, 5e
Multiple Selection: Nested if (continued)
![Page 38: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/38.jpg)
38Java Programming: From Problem Analysis to Program Design, 5e
![Page 39: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/39.jpg)
39Java Programming: From Problem Analysis to Program Design, 5e
![Page 40: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/40.jpg)
40Java Programming: From Problem Analysis to Program Design, 5e
• Definition: a process in which the computer evaluates a logical expression from left to right and stops as soon as the value of the expression is known
Short-Circuit Evaluation
![Page 41: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/41.jpg)
41Java Programming: From Problem Analysis to Program Design, 5e
Short-Circuit Evaluation (continued)
![Page 42: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/42.jpg)
42Java Programming: From Problem Analysis to Program Design, 5e
![Page 43: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/43.jpg)
43Java Programming: From Problem Analysis to Program Design, 5e
![Page 44: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/44.jpg)
44Java Programming: From Problem Analysis to Program Design, 5e
![Page 45: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/45.jpg)
45Java Programming: From Problem Analysis to Program Design, 5e
• The preceding program and its output show that you should be careful when comparing floating-point numbers for equality.
• One way to check whether two floating-point numbers are equal is to check whether the absolute value of their difference is less than a certain tolerance. For example, suppose the tolerance is .000001.
• Then x and y are equal if the absolute value of (x – y) is less than 0.000001. To find the absolute value, you can use the function Math.abs of the class Math, as shown in the program.
• Therefore, the expression Math.abs(x – y) < 0.000001 determines whether the absolute value of (x – y) is less than 0.000001.
![Page 46: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/46.jpg)
46Java Programming: From Problem Analysis to Program Design, 5e
Conditional (? :) Operator
• Ternary operator
• Syntaxexpression1 ? expression2 : expression3
• If expression1 = true, then the result of the condition is expression 2; otherwise, the result of the condition is expression 3
![Page 47: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/47.jpg)
47Java Programming: From Problem Analysis to Program Design, 5e
![Page 48: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/48.jpg)
48Java Programming: From Problem Analysis to Program Design, 5e
![Page 49: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/49.jpg)
49Java Programming: From Problem Analysis to Program Design, 5e
![Page 50: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/50.jpg)
50Java Programming: From Problem Analysis to Program Design, 5e
![Page 51: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/51.jpg)
51Java Programming: From Problem Analysis to Program Design, 5e
switch Structures
![Page 52: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/52.jpg)
52Java Programming: From Problem Analysis to Program Design, 5e
switch Structures (continued)
• In Java, switch, case, break, and default are reserved words
• In a switch structure, the expression is evaluated first
• The value of the expression is then used to perform the actions specified in the statements that follow the reserved word case
• The expression is usually an identifier • The value of the identifier or the expression can be only of type int, byte, short, or char
![Page 53: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/53.jpg)
switch Structures (continued)
Java Programming: From Problem Analysis to Program Design, 5e 53
• The expression is sometimes called the selector; its value determines which statements are selected for execution
• A particular case value must appear only once• One or more statements may follow a case
label, so you do not need to use braces to turn multiple statements into a single compound statement
![Page 54: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/54.jpg)
switch Structures (continued)
Java Programming: From Problem Analysis to Program Design, 5e 54
• The break statement may or may not appear after each statements1, statements2, ..., statementsn
• A switch structure may or may not have the default label
![Page 55: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/55.jpg)
55Java Programming: From Problem Analysis to Program Design, 5e
switch Structures (continued)
![Page 56: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/56.jpg)
56Java Programming: From Problem Analysis to Program Design, 5e
switch Structures (continued)
![Page 57: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/57.jpg)
57Java Programming: From Problem Analysis to Program Design, 5e
Example 4-20
switch (grade){case 'A': System.out.println("The grade is A."); break;
case 'B': System.out.println("The grade is B."); break;
case 'C': System.out.println("The grade is C."); break;
switch Structures (continued)
![Page 58: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/58.jpg)
58Java Programming: From Problem Analysis to Program Design, 5e
case 'D': System.out.println("The grade is D."); break;
case 'F': System.out.println("The grade is F."); break;
default: System.out.println("The grade is invalid.");}
switch Structures (continued)
![Page 59: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/59.jpg)
59Java Programming: From Problem Analysis to Program Design, 5e
![Page 60: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/60.jpg)
60Java Programming: From Problem Analysis to Program Design, 5e
![Page 61: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/61.jpg)
61Java Programming: From Problem Analysis to Program Design, 5e
![Page 62: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/62.jpg)
62Java Programming: From Problem Analysis to Program Design, 5e
To output results correctly, the switch structure must include a break statement after each println statement, except the last println statement.
![Page 63: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/63.jpg)
63Java Programming: From Problem Analysis to Program Design, 5e
Programming Example: Cable Company Billing
• Input: customer’s account number, customer code, number of premium channels to which customer subscribes, number of basic service connections (in case of business customers)
• Output: customer’s account number and the billing amount
![Page 64: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/64.jpg)
64Java Programming: From Problem Analysis to Program Design, 5e
Programming Example: Cable Company Billing (continued)
• Solution – Prompt user for information– Use switch statements based on customer’s
type– Use an if statement nested within a switch
statement to determine amount due by each customer
![Page 65: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/65.jpg)
65Java Programming: From Problem Analysis to Program Design, 5e
Comparing Strings
• class String – Method compareTo– Method equals
• Given string str1 and str2
str2str1 0
str2str1 0
str2str1 0
reTo(str2)str1.compa
string ifinteger an
string toequal is string if
string ifinteger an
![Page 66: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/66.jpg)
66Java Programming: From Problem Analysis to Program Design, 5e
Comparing Strings (continued)String str1 = "Hello";
String str2 = "Hi";
String str3 = "Air";
String str4 = "Bill";
String str5 = "Bigger";
![Page 67: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/67.jpg)
67Java Programming: From Problem Analysis to Program Design, 5e
Comparing Strings (continued)
![Page 68: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/68.jpg)
68Java Programming: From Problem Analysis to Program Design, 5e
Comparing Strings (continued)
![Page 69: 9781111530532 ppt ch04](https://reader036.fdocuments.net/reader036/viewer/2022081507/555c3de5d8b42a0b038b4c1d/html5/thumbnails/69.jpg)
69Java Programming: From Problem Analysis to Program Design, 5e
Chapter Summary
• Control structures are used to process programs• Logical expressions and order of precedence of
operators are used in expressions• If statements• if…else statements• switch structures• Proper syntax for using control statements• Compare strings