1 Chapter 6 Repetition. 2 Outline & Objectives Loop Structure Loop Structure Elements of a Loop Structure Elements of a Loop Structure Processing Lists.

Slides:



Advertisements
Similar presentations
Objectives In this chapter, you will learn about:
Advertisements

Repeating Actions While and For Loops
Computer Science 1620 Loops.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
Types of LOOP Structures Do While ……. Loop Do Until …… Loop For …… Next loop.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Chapter 6 - VB.Net by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops Peek Method Counters and Accumulators Flags.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
Chapter 6 - Visual Basic Schneider
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Introduction to Computing Dr. Nadeem A Khan. Lecture 8.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Repetition Statements.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 6 Repetition Statements.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops.
CIS 115 Lecture 8. There are 3 control structures common to most computer languages that determine the flow, or path of execution, of the code:  Sequential.
ENGR 112 Decision Structures.
Repetitive Structures BBS514 Structured Programming (Yapısal Programlama)1.
Programming Logic and Design Sixth Edition Chapter 5 Looping.
Copyright © Nancy Acemian 2004 For Loops-Break-Continue COMP For loop is a counter controlled loop. For loop is a pretest loop. Used when number.
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 6 - Visual Basic Schneider 1 Chapter 6 Repetition.
CHAPTER SIX LOOPS © Prepared By: Razif Razali 1. FORMAT OR REFRESH!! WHAT HAVE WE LEARN? Differentiate between the types of selection structure? Which.
Chapter 71 Repetition - Do Loops n A Loops, is used to repeat a sequence of statements a number of time n There are two loops commands in Visual Basic.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Loop.  While Loop  Do-while Loop  For Loop Continue Statement Conclusion Loop Loop.
PROBLEM SOLVING WITH LOOPS Chapter 7. Concept of Repetition Structure Logic It is a computer task, that is used for Repeating a series of instructions.
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
Chapter 6 - VB.Net by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops Peek Method Counters and Accumulators Flags.
Count and add list of numbers From user input and from file.
Repetition Chapter 6 - Visual Basic Schneider 1  Loop Structure  Elements of a Loop Structure  Processing Lists of Data with Do Loops Chapter 6 -
Repetition Structures
Chapter 5: Control Structures: Iteration Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study:
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
1 Standard Version of Starting Out with C++, 4th Brief Edition Chapter 5 Looping.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Controlling Program Flow with Looping Structures
Chapter Looping 5. The Increment and Decrement Operators 5.1.
REPETITION MTS3033 OBJECT ORIENTED PROGRAMMING 1.
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.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Chapter Looping 5. The Increment and Decrement Operators 5.1.
CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
Problem Solving and Program Design in C Chap. 5 Repetition and Loop Statement Chow-Sing Lin.
Chapter 6 - VB 2008 by Schneider1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study:
1 Chapter 6 – Repetition 6.1 Do Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops 6.4 A Case Study: Analyze a Loan.
CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad.
REPETITION CONTROL STRUCTURE
Chapter 5: Control Structures II
Chapter 2.2 Control Structures (Iteration)
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Outline Altering flow of control Boolean expressions
Iteration: Beyond the Basic PERFORM
3 Control Statements:.
Chapter 2.2 Control Structures (Iteration)
Chapter 6 - VB.Net by Schneider
Topics Introduction to Repetition Structures
For...Next Statements.
Presentation transcript:

1 Chapter 6 Repetition

2 Outline & Objectives Loop Structure Loop Structure Elements of a Loop Structure Elements of a Loop Structure Processing Lists of Data with Do Loops Processing Lists of Data with Do Loops

3 Types of LOOP Structures Do While ……. Loop Do While ……. Loop Do Until …… Loop Do Until …… Loop For …… Next loop For …… Next loop

4 Basic Definition Looping: the process of repeating a series of statements multiple times until a criteria is met Looping: the process of repeating a series of statements multiple times until a criteria is met

5 Basic Components of Loops Loop control variable: A variable used to determine whether a loop will be executed Loop control variable: A variable used to determine whether a loop will be executed Loop body: The statement (s) that are executed each time a loop repeats Loop body: The statement (s) that are executed each time a loop repeats

6 The Do While ……. Loop Do While condition is true statement(s) statement(s)Loop

7 Flowchart for a Do While Loop Is the condition true Execute statements within the loop Execute statements that follow the loop Yes No

8 Example (Displays the numbers from 1 through 10) Private Sub cmdDisplay_Click() Dim num As Integer Dim num As Integer ' Display the numbers from 1 to 10 ' Display the numbers from 1 to 10 num = 1 num = 1 Do While num <= 10 Do While num <= 10 picNumbers.Print num; picNumbers.Print num; num = num + 1 num = num + 1 Loop Loop End Sub

9 The Do While ……. Loop Is executed as long as the condition is True. Is executed as long as the condition is True. If condition is False then the next statement after the Loop is executed. If condition is False then the next statement after the Loop is executed.

10 Controlling Loops Methods of controlling loops: Methods of controlling loops: Counter-controlled loopsCounter-controlled loops repeat a specific number of timesrepeat a specific number of times Event-controlled loopsEvent-controlled loops repeat until something happens in the loop body to change the value of loop control variable.repeat until something happens in the loop body to change the value of loop control variable.

11 Example of event-controlled loops passWord = "" Do While passWord <> “ ADMIN" passWord = UCase(InputBox("What is the password?")) passWord = UCase(InputBox("What is the password?"))Loop

12 Counter-controlled Loops Is useful when the programmer knows how many times the loop should be executed. Is useful when the programmer knows how many times the loop should be executed. Initialize the counter by setting it to a beginning value before entering the loop. Initialize the counter by setting it to a beginning value before entering the loop. The counter is incremented (or decremented) by the same value during each repetition. The counter is incremented (or decremented) by the same value during each repetition.

13 Example num = 1 Do While num <= 10 picOutput.Print num; picOutput.Print num; num = num + 1 num = num + 1Loop

14Example

15 Dim x As Integer Dim s As Integer Do While x >= 2 x = x + 1 s = s + x Loop picOutput.Print x; s Example

16 Dim x As Integer Dim s As Integer Do While x <= 5 If x <= 2 Then x = x + 2 x = x + 2Else x = x + 1 x = x + 1 End If s = s + x Loop picOutput.Print x; s Example

17Example

18 Dim x As Integer Dim s As Integer Do x = x + 1 s = s + x Loop While x >= 2 picOutput.Print x; s Example

19 Try solving the following Problems 1. Write a program to print numbers from 1 to Print 10 to 1 3. Print 50 to Print the even [odd] numbers from 1 to Summation of numbers from 100 to Average of 10 marks 7. Find max, min

20 Do Until ……. Loop Is executed until the condition becomes True Is executed until the condition becomes True Any Do While …. Loop can be rewritten as a Do Until ….. Loop Any Do While …. Loop can be rewritten as a Do Until ….. Loop

21 Dim x As Integer Dim s As Integer Do Until x >= 2 x = x + 1 s = s + x Loop picOutput.Print x; s Example

22 Dim x As Integer Dim s As Integer Do x = x + 1 s = s + x Loop Until x >= 2 picOutput.Print x; s Example

23 Dim x As Integer Dim s As Integer Do x = x + 1 s = s + x Loop Until x <= 2 picOutput.Print x; s Example

24 Example (requires the user to give a password before opening a file) Private Sub cmdDisplay_Click() Dim passWord As String, info As String Dim passWord As String, info As String If UCase(txtName.Text) = "SECRET.TXT" Then If UCase(txtName.Text) = "SECRET.TXT" Then Do Do passWord = UCase(InputBox("What is the password?")) passWord = UCase(InputBox("What is the password?")) Loop Until passWord = "SHAZAM" Loop Until passWord = "SHAZAM" End If End If Open txtName.Text For Input As #1 Open txtName.Text For Input As #1 Input #1, info Input #1, info picItem.Cls picItem.Cls picItem.Print info picItem.Print info Close #1 Close #1 End Sub

25 Example (years to deplete a saving account) Private Sub cmdEstimate_Click() Dim amt As Single, yrs As Integer Dim amt As Single, yrs As Integer ' Years to deplete savings account ' Years to deplete savings account picResult.Cls picResult.Cls amt = amt = yrs = 0 yrs = 0 Do Do amt = amt * amt = amt * yrs = yrs + 1 yrs = yrs + 1 Loop Until amt <= 0 Loop Until amt <= 0 picResult.Print "It takes"; yrs; "years to deplete the account." picResult.Print "It takes"; yrs; "years to deplete the account." End Sub

26 Comparing While… and Until Loops The Do While … Loop executes while the condition is true The Do While … Loop executes while the condition is true The Do Until ….. Loop executes until the condition is true The Do Until ….. Loop executes until the condition is true Both can be used to create any type of loop Both can be used to create any type of loop

27 Converting While loop to Until loop Do While Condition Action(s)Loop Do Until Not(Condition) Action(s)Loop Equivalents to Do While x <= y Action(s)Loop Do Until x > y Action(s)Loop Equivalents to Do While x =10 Action(s)Loop Do Until Not(x =10) Action(s) Loop Equivalents to

28 Review num = 11 Do While num <= 10 picOutput.Print num; picOutput.Print num; num = num + 1 num = num + 1Loop num = 11 Do picOutput.Print num; num = num + 1 Loop until num <= 10 How many times will the following loops execute? 0 Infinite loop

29 Review i = 1 Do While i < 10 i = i + 1 i = i + 1Loop i = 0 Do i = i + 1 Loop While i < 10 Which loop is infinite? i = 11 Do Until i < 10 Loop i = 0 Do i = i + 10 Loop Until i < 10 NO Yes

30 EOF Function EOF(n) is True if the end of the file having reference number n has been reached. Otherwise, it is False EOF(n) is True if the end of the file having reference number n has been reached. Otherwise, it is False

31 Dim count As Integer count = 1 Open “DATA.TXT” For Input As #1 Do While NOT EOF(1) Input #1, x Input #1, x count= count + 1 s = s + x Loop will be true if the end of file has been reached, and false otherwise If all entries in the file are read, the EOF returns True When the file is opened, the EOF returns False until all entries in the file are readExample

32 Counters and Accumulators A counter is a numeric variable that keeps track of the number of items that have been processed in a loop. A counter is a numeric variable that keeps track of the number of items that have been processed in a loop. An accumulator is a numeric variable that holds a sub-total during multiple passes through a loop. An accumulator is a numeric variable that holds a sub-total during multiple passes through a loop.

33 Example: Counter & Accumulator Private Sub cmdAnalyze_Click() Dim numCoins As Integer, sum As Single Dim numCoins As Integer, sum As Single Dim value As Single Dim value As Single Open "COINS.TXT" For Input As #1 Open "COINS.TXT" For Input As #1 numCoins = 0 numCoins = 0 sum = 0 sum = 0 Do While Not EOF(1) Do While Not EOF(1) Input #1, value Input #1, value numCoins = numCoins + 1 numCoins = numCoins + 1 sum = sum + value sum = sum + value Loop Loop picValue.Print "The value of the"; numCoins; "coins is"; sum; "cents." picValue.Print "The value of the"; numCoins; "coins is"; sum; "cents." End Sub COINS.TXT

34 Compare Do While ……. Loop Do While ……. Loop Do ……. Loop While Do ……. Loop While Do ……. Loop Until Do ……. Loop Until Do Until ……. Loop Do Until ……. Loop

35 How many times the following code executes the print statement a = 0 a = 0 Do Do Print a + 1 Print a + 1 Loop Until a <= 10 Loop Until a <= 10 1

36 How many times the following code executes the print statement a = 1 a = 1 Do Until a < 10 Do Until a < 10 Print a + 2 Print a + 2 Loop Loop 0

37 How many times the following code executes the print statement a = 0 a = 0 Do Do Print a + 1 Print a + 1 Loop While a <= 10 Loop While a <= 10 a = 1 a = 1 Do While a < 10 Do While a < 10 Print a + 2 Print a + 2 Loop Loop Infinite loop

38 What is the output of the following code Dim month As Integer x = 1 Do Select Case (x / 2 - 2) Select Case (x / 2 - 2) Case 0 Case 0 Print x; Print x; End Select End Select x = x + 1 x = x + 1 Loop Until (x > 5) 4

39 What is the value of x after the following code executes? f = True x = 10 Do While (f) If (x / 4 = 1) Then f = False If (x / 4 = 1) Then f = False x = x - 1 x = x - 1Loop Print x 3

40 Assume that the file Data.txt contains the following entries: Assume that the file Data.txt contains the following entries: 1, 9, 5, 3, 7, 4, 9, 2, 1, 1, 5 and the file Numbers.txt contains the following entries: and the file Numbers.txt contains the following entries:2,4,5,1Example

41 What is the output of the following code? Dim y As Integer Open "Data.txt" For Input As #1 Open "Numbers.txt" For Input As #2 Do Input #1, x Input #1, x If x < 7 Then If x < 7 Then Input #2, y Input #2, y End If End If Print x + y; Print x + y; Loop Until EOF(1) Or EOF(2)

42 What is the output of the following code? Do While x <= 10 x = x + 10 x = x + 10 c = c + 1 c = c + 1Loop Do Until x > 20 x = x * 2 x = x * 2 c = c + 1 c = c + 1Loop Picture1.Print x; c 40 3

43 Which one of the following code is an infinite loop? Dim x as integer Do Until x<>2 Loop Dim x as integer, y as integer x=10 y=0 Do While x + y = 10 x=x+1 y=y-1 Loop

44 Are the following code infinite loops? Dim x as integer Do Loop while x <> 0 Dim x as integer x=0 do x=10 Loop Until x=10

45 What is the output of the following code? x = 0 y = 0 Do While x > 10 Or y 10 Or y < 10 y = y + x y = y + x x = y x = yLoop Print x; y Infinite loop

46 Which one of the following code has the correct syntax of "Do Loop Until" structure? x= 20 Do Loop x=x-1 print x Until x<10 x= 20 Loop x=x-1 print x Do Until x<10 x=20 Do x=x-1 print x Loop Until x<10 x=20 Do x=x-1 print x Loop Until

47 What is the output of the following code? Assume the contents of S.txt are: 1.5, 4.2, 9.7, 3.8 Assume the contents of S.txt are: 1.5, 4.2, 9.7, 3.8 Dim s As Single Open "S.txt" For Input As #1 Do Input #1, s Input #1, s Loop Until EOF(1) Input #1, s Pic.Print s; Close #1 Run-time error

48 What is the output of the following code? Assume the contents of r1.txt are: 2,4,6 Assume the contents of r1.txt are: 2,4,6 Dim r As Integer, m As Integer m = 1 Open "r1.txt" For Input As #1 Do Input #1, r Input #1, r m = m * r m = m * r Loop While EOF(1) Pic.Print m; Close #1 2

49 How many stars (asterisks "*") will the following code print? x = 1 Do While x <= 3 y = 0 y = 0 Do Until y = x Do Until y = x Picture1.Print "*" Picture1.Print "*" y = y + 1 y = y + 1 Loop Loop x = x + 1 x = x + 1Loop 6

50 What is the output of the following code? Dim i As Integer i = 2 Do While i <= 9 Select Case i Case 1 Case 1 Case Is > 5 Case Is > 5 output = output & "A" output = output & "A" Case 3 To 6 Case 3 To 6 output = output & "B" output = output & "B" Case Else Case Else output = output & "C" output = output & "C" End Select End Select i = i +3 loop Print output CBA

51 For … Next Loop A loop where the number of iterations is determined by a range of values for a numeric variable A loop where the number of iterations is determined by a range of values for a numeric variable Syntax: Syntax: For controlVariable = initial To terminal statement(s) statement(s) Next controlVariable

52 Example Private Sub cmdDisplayTable_Click() Dim i As Integer Dim i As Integer ‘Display a table of the first 5 numbers and their squares ‘Display a table of the first 5 numbers and their squares For i = 1 To 5 For i = 1 To 5 picTable.Print i; i ^ 2 picTable.Print i; i ^ 2 Next i End Sub Initial Value Control variable Terminating value

53 Example Dim numVar As Integer For numVar = 1 To 5 Step 2 picOutput.Print numVar; picOutput.Print numVar; Next numVar Output: 1 3 5

54 When a For statement is encountered 1. The control variable is assigned the initial value. 2. After each loop iteration, the step value is added to the value of the control variable. (If there is no step value, 1 is added.) 3. Iteration continues until the terminating value is exceeded.

55 Rules for Using For... Next loop You should never modify the value of the loop control variable in the loop body. You should never modify the value of the loop control variable in the loop body. Each For loop must end with a Next statement. Each For loop must end with a Next statement.

56 Example Private Sub cmdDisplay_Click() Dim i As Integer Dim i As Integer For i = 1 To 10 For i = 1 To 10 picOutput.Print "*"; picOutput.Print "*"; Next i Next i End Sub Output: **********

57 Example Private Sub cmdDisplay_Click() Dim i As Integer, stars As Integer Dim i As Integer, stars As Integer stars = Val(InputBox("Row length (1-20) :")) stars = Val(InputBox("Row length (1-20) :")) For i = 1 To stars For i = 1 To stars picOutput.Print "*"; picOutput.Print "*"; Next i Next i End Sub

58 Example Dim numVar As Integer For numVar = 8 To 1 Step -2 picOutput.Print numVar; picOutput.Print numVar; Next numVar Output:

59

60 Private Sub Command1_Click() For x = 1 To 3 Step 0 Print x; Next Print " finally "; x End Sub Infinite loop

61 Nested Loops For outer = 1 To 4 For inner = 1 To 2 For inner = 1 To Next inner Next inner Next outer

62 Example: Display a 3x3 rectangle of stars Private Sub cmdDisplay_Click() Dim i As Integer, j As Integer Dim i As Integer, j As Integer For i = 1 To 3 For i = 1 To 3 For j = 1 To 3 For j = 1 To 3 picOutput.Print "*"; picOutput.Print "*"; Next j Next j picOutput.Print picOutput.Print Next i Next i End Sub ***

63 Review For i= -5 To -1 Step - 2 picOutput.Print i; picOutput.Print i; Next i picOutput.Print i; For i= 1 To 5 Step 2 i=i+1 picOutput.Print i; Next i picOutput.Print i;

64 Review Private Sub cmdDisplay_Click() Dim i As Integer, j As Integer Dim i As Integer, j As Integer For i = 1 To 3 For i = 1 To 3 For j = i To 3 For j = i To 3 picOutput.Print "*"; picOutput.Print "*"; Next j Next j picOutput.Print picOutput.Print Next i Next i End Sub Private Sub cmdDisplay_Click() Dim i As Integer, j As Integer Dim i As Integer, j As Integer For i = 1 To 3 For i = 1 To 3 For j = 1 To i For j = 1 To i picOutput.Print "*"; picOutput.Print "*"; Next j Next j picOutput.Print picOutput.Print Next i Next i End Sub *** ** * ** ***

65 How many times the statement print "Good Luck" will be executed Dim i as integer, j as integer Dim i as integer, j as integer for i=0 To 3 for i=0 To 3 for j=0 To 0 for j=0 To 0 print "Good Luck" print "Good Luck" Next j Next j Next i Next i 4

66 What is the output of the following code Dim a as integer a=5 a=5 for a=3 To 1 step -1 for a=3 To 1 step -1 print a; print a; Next a Next a print a print a

67 which of the following statements is true about the following code For i = -7 To -3 pic1.Print i pic1.Print i Next i This code will print numbers from -7 to -3 starting from -3 This code will print numbers from -7 to -3 starting from -3 This code will print numbers from -7 to -3 starting from -7 This code will print numbers from -7 to -3 starting from -7 This code will print all numbers less than -7 This code will print all numbers less than -7 This code will print all numbers greater than -7 This code will print all numbers greater than -7

68 which of the following statements is true about the following code For i = 1 To 5.8 Step 1 pic1.Print i; pic1.Print i; Next I This code will print numbers from 1 to 6 This code will print numbers from 1 to 6 This code will print numbers from 1 to 5 This code will print numbers from 1 to 5 Run-time error Run-time error This code will print numbers from 1 to 5.8 This code will print numbers from 1 to 5.8

69 What is the output of the following code? Dim i As Integer Dim i As Integer For i = 9 To 7 For i = 9 To 7 Print i; Print i; Next i Next i Nothing will be printed Nothing will be printed

70 What is the output of the following code? Dim i as integer Dim i as integer i=4 i=4 for i=3 To 5 for i=3 To 5 print 2*i; print 2*i; Next i Next i print i print i

71 Dim a as integer Dim a as integer a=5 a=5 for a=3 To 1 step -1 for a=3 To 1 step -1 print a; print a; Next a Next a print a print a Example

72 Dim x as integer x = 0 for x=3 To 1 print x; print x; Next x print x 3Example

73 How many stars (*) are printed when the following code is executed? Dim i as Integer Dim i as Integer for i = 1 To 6 Step 1 for i = 1 To 6 Step 1 print "*" print "*" i=i+2 i=i+2 next i next i 2 stars

74 Boolean data type: a variable that stores only two values (True or False) Example Example