Chapter 6 Repetition

Size: px
Start display at page:

Download "Chapter 6 Repetition"

Transcription

1 hapter 6 Repetition Section 6.1 o Loops 1. What is wrong with the following o loop? im index As Integer = 1 o While index <> 9 lstbox.items.add("hello") index += 1 Loop (A) he test variable should not be changed inside a o loop. (B) he test condition will never be true. () his is an infinite loop. () Nothing 2. What numbers will be displayed in the list box when the button is clicked? Private Sub btnisplay_lick(...) Handles btnisplay.lick im num as ouble = 10 o While num > 1 lstbox.items.add(num) num = num - 3 Loop (A) 10, 7, and 4 (B) 10, 7, 4, and 1 () 10, 7, 4, 1, and -2 () No output A 3. Which While statement is equivalent to Until num < 100? (A) While num <= 100 (B) While num > 100 () While num >= 100 () here is no equivalent While statement.

2 4. What is wrong with the following o loop? im index As Integer = 1 o While index <> 10 lstbox.items.add("hello") index += 2 Loop (A) It should have been written as a o Until loop. (B) It is an infinite loop. () he test variable should not be changed within the loop itself. () Nothing B 5. How many times will the word Happy appear in the list box when the following code is executed? im index As Integer o lstbox.items.add("happy") index += 1 Loop While index > 3 (A) 0. (B) 1 () 2 () 3 B 6. In analyzing the solution to a program, you conclude that you want to construct a loop so that the loop terminates either when (a < 12) or when (b = 16). Using a o loop, the test condition should be (A) o While (a > 12) Or (b <> 16) (B) o While (a >= 12) Or (b <> 16) () o While (a < 12) Or (b <> 16) () o While (a >= 12) And (b <> 16) (E) o While (a < 12) And (b = 16) 7. When Visual Basic executes a o While loop it first checks the truth value of the. (A) pass (B) loop () condition () statement

3 8. If the loop is to be executed at least once, the condition should be checked at the. (A) top of the loop (B) middle of the loop () bottom of the loop () Nothing should be checked. 9. A o While loop checks the While condition before executing the statements in the loop. (/) 10. If the While condition in a o While loop is false the first time it is encountered, the statements in the loop are still executed once. (/) 11. he following statement is valid. (/) o While x <> he following two sets of code produce the same output. (/) im num As Integer = 1 im num As Integer = 1 o While num <= 5 o lstbox.items.add("hello") lstbox.items.add("hello") num += 1 num += 1 Loop Loop Until (num > 5) 13. A loop written using the structure o While...Loop can usually be rewritten using the structure o...loop Until. (/) 14. A variable declared inside a o loop cannot be referred to outside of the loop. (/) 15. escribe precisely the output produced by the following segment for the inputs 4 and 2. im last, i As Integer last = Int(InputBox("Enter terminating value:")) i = 0 o While (i <= last) lstbox.items.add(i) i += 1 Loop (Input 4): (Input 2): No output

4 16. he following is an infinite loop. Rearrange the statements so that the loop will terminate as intended. x = 0 o lstbox.items.add(x) Loop Until x > 13 x += 2 Move the last statement one line up, before the Loop Until statement 17. What is wrong with the following simple password program where today's password is "intrepid"? Private Sub btnisplay_lick(...) Handles btnisplay.lick im password As String password = InputBox("Enter today's password:") o lstbox.items.add("incorrect") password = InputBox("Enter today's password:") Loop Until password = "intrepid" lstbox.items.add("password orrect. You may continue.") (A) here is no way to re-enter a failed password. (B) he Loop Until condition should be password <> "intrepid". () It will display "Incorrect." even if the first response is "intrepid". () Nothing 18. How many times will HI be displayed when the following lines are executed? im c As Integer = 12 o lstbox.items.add("hi") c += 3 Loop Until (c >= 30) (A) 5 (B) 9 () 6 () 4 (E) 10

5 19. In the following code segment, what type of variable is counter? im temp, counter, check As Integer o temp = Int(InputBox("Enter a number.")) counter += temp If counter = 10 hen check = 0 End If Loop Until (check = 0) (A) counter (B) accumulator () sentinel () loop control variable B 20. What numbers will be displayed in the list box by the following code when the button is clicked? Private Sub btnisplay_lick(...) Handles btnisplay.lick im num As Integer = 7 o num += 1 lstbox.items.add(num) Loop Until (num > 6) lstbox.items.add(num) (A) 7 (B) 8 () 7 and 8 () 8 and calculate the number of elements in lists. (A) Sentinels (B) ounter variables () Accumulators () Nested loops B 22. calculate the sums of numerical values in lists. (A) Sentinels (B) ounter variables () Accumulator variables () Nested loops

6 23. he following are equivalent While and Until statements. (/) While (num > 2) And (num < 5) Until (num <= 2) Or (num >= 5) 24. A o Loop Until block is always executed at least once. (/) 25. A counter variable is normally incremented or decremented by 1. (/) 26. he following program uses a counter variable to force the loop to end. (/) Private Sub btnisplay_lick(...) Handles btnisplay.lick im r As ouble = 1 im t As ouble = 0 o While (t < 5000) t = 2 * t + r r += 1 lstbox.items.add(t) Loop Section 6.2 or Loops 1. When the number of repetitions needed for a set of instructions is known before they are executed in a program, the best repetition structure to use is a(n) (A) o While...Loop structure. (B) o...loop Until structure. () or... loop. () If block. 2. What is one drawback in using non-integer Step sizes of type ouble? (A) Round-off errors may cause unpredictable results. (B) Non-integer Step sizes are invalid in Visual Basic. () A non-integer Step size is never needed. () Non-integer Step sizes usually produce infinite loops. A

7 3. When the odd numbers are added successively, any finite sum will be a perfect square (e.g., = 9 and 9 = 3^2). What change must be made in the following program to correctly demonstrate this fact for the first few odd numbers? Private Sub btnisplay_lick(...) Handles btnisplay.lick im oddnumber As Integer im sum As Integer = 0 or i As Integer = 1 o 9 Step 2 'Generate first few odd numbers oddnumber = i or j As Integer = 1 o oddnumber Step 2 'Add odd numbers sum += j lstbox.items.add(sum & " is a perfect square.") (A) hange the Step size to 1 in the first or statement. (B) Move oddnumber = i inside the second or loop. () Reset sum to zero immediately before the second statement. () Reset sum to zero immediately before the first statement. 4. What does the following program do with a person's name? Private Sub btnisplay_lick(...) Handles btnisplay.lick im name, test As String im n As String = "" name = InputBox("Enter your first name:") or i As Integer = 0 o (name.length - 1) Step 2 test = name.substring(i, 1) n = test & n txtbox.ext = n It displays the name (A) in reverse order. (B) in reverse order and skips every other letter. () as it was entered. () as it was entered, but skips every other letter. B 5. Suppose the days of the year are numbered from 1 to 365 and January 1 falls on a uesday as it will in What is the correct or statement to use if you want only the numbers for the ridays in 2019? (A) or i As Integer = 3 to 365 Step 7 (B) or i As Integer = 1 to 365 Step 3 () or i As Integer = 365 o 1 Step -7 () or i As Integer = 3 o 365 Step 6 A

8 6. Given the following partial program, how many times will the statement lstbox.items.add(j + k + m) be executed? or j As Integer = 1 o 4 or k As Integer = 1 o 3 or m As Integer = 2 o 10 Step 3 lstbox.items.add(j + k + m) (A) 24 (B) 60 () 36 () 10 (E) None of the above 7. Which of the following program segments will sum the eight numbers input by the user? (A)or k As Integer = 1 o 8 s = bl(inputbox("enter a number.") s += k (B) or k As Integer = 1 o 8 a = bl(inputbox("enter a number.") s += 1 () or k As Integer = 1 o 8 a = bl(inputbox("enter a number.") a += s () or k As Integer = 1 o 8 a = bl(inputbox("enter a number.")) s += a

9 8. What will be displayed by the following program when the button is clicked? Private Sub btnisplay_lick(...) Handles btnisplay.lick im a As String, n, c As Integer a = "HIGHBAK" n = Int(Int(a.Length / 2)) c = 0 or k As Integer = 0 o n 1 If a.substring(k, 1) > a.substring(7 k, 1) hen c += 1 End If txtbox.ext = Str(c) (A) 1 (B) 2 () 3 () 4 (E) 5 9. In a or statement of the form shown below, what is the default step value when the "Step c" clause is omitted? or i As Integer = a o b Step c (A) the same as a (B) the same as b () 0 () What will be displayed when the following lines are executed? txtbox.lear() or k As Integer = 1 o 3 txtbox.ext &= "AB".Substring(4 k, 1) (A) AB (B) BA () BA () BA (E) B E

10 11. Which loop computes the sum of 1/2 + 2/3 + 3/4 + 4/ /100? (A) or n As Integer = 1 o 99 s += n / (1 + n) (B) or q As Integer = 100 o 1 s += (q + 1) /q () or d As Integer = 2 o 99 s = 1 / d + d / (d + 1) () or x As Integer = 1 o 100 s += 1 / (x + 1) A 12. How many times will PEE be displayed when the following lines are executed? or c As Integer = 15 to -4 Step -6 lstbox.items.add("pee") (A) 1 (B) 2 () 3 () What will be displayed by the following program when the button is clicked? Private Sub btnisplay_lick(...) Handles btnisplay.lick im s As ouble s = 0 or k As Integer = 1 o 5 If k / 2 = Int(k / 2) hen s += k End If txtbox.ext = Str(s) (A) 12 (B) 9 () 15 () 6

11 14. How many lines of output are produced by the following program segment? or i As Integer = 1 o 3 or j As Integer = 1 o 3 or k As Integer = i to j lstbox.items.add("programming is fun.") (A) 8 (B) 9 () 10 () Assuming the following statement, what is the or... loop's counter variable? or yr As Integer = 1 o 5 (A) 1 (B) 5 () o () yr 16. What is the value of j after the end of the following code segment? or j As Integer = 1 to 23 lstbox.items.add("he counter value is " & j) (A) 22 (B) 23 () 24 () j no longer exists 17. A or... loop with a positive step value continues to execute until what condition is met? (A) he counter variable is greater than the terminating value. (B) he counter variable is equal to or greater than the terminating value. () he counter variable is less than the terminating value. () he counter variable is less than or equal to the terminating value. A

12 18. Which of the following loops will always be executed at least once when it is encountered? (A) a or... loop (B) a o loop having posttest form () a o loop having pretest form () none of the above. B 19. Which of the following are valid for an initial or terminating value of a or... loop? (A) a numeric literal (B) info.length, where info is a string variable () a numeric expression () All of the above 20. What is the data type of the variable num if Option Infer is set to On and the statement im num = 7.0 is executed? (A) Integer (B) ecimal () ouble () String (E) Boolean 21. he value of the counter variable should not be altered within the body of a or loop. (/) 22. he body of a or... loop in Visual Basic will always be executed once no matter what the initial and terminating values are. (/) 23. If the terminating value of a or... loop is less than the initial value, then the body of the loop is never executed. (/) 24. If one or... loop begins inside another or... loop, it must also end within this loop. (/) 25. he value of the counter variable in a or... loop need not be a whole number. (/) 26. One must always have a statement paired with a or statement. (/)

13 27. If the initial value is greater than the terminating value in a or... loop, the statements within are still executed one time. (/) 28. When one or... loop is contained within another, the name of the counter variable for each or... loop may be the same. (/) 29. A or... loop cannot be nested inside a o loop. (/) 30. he following code segment is valid. (/) If (firstletter > "A") hen or x As Integer = 1 to 100 lstbox.items.add(x) End If 31. In a or... loop, the initial value should be greater than or equal to the terminating value if a negative step is used and the body of the loop is to be executed at least once. (/) 32. If the counter variable of a or... loop will assume values that are not whole numbers, then the variable must not be of type Integer. (/) 33. he step value of a or... loop can be given by a numeric literal, variable, or expression. (/) 34. he variable index declared with the statement or index As Integer = 0 o 5 cannot be referred to outside of the or loop. (/) 35. When Option Infer is set to On, a statement of the form im num = 7 is valid. (/)

14 36. What is displayed in the text box when the button is clicked? Private Sub btnisplay_lick(...) Handles btnisplay.lick im word As String = "Alphabet" im abbreviation As String = "" or i As Integer = 0 o word.length - 1 If word.substring(i, 1).oUpper <> "A" hen abbreviation &= word.substring(i, 1) End If txtbox.ext = abbreviation lphbet Section 6.3 List Boxes and Loops 1. Which of the following expressions refers to the contents of the last row of the list box? (A) lstbox.items(lstbox.items.ount) (B) lstbox.items(lstbox.items.ount - 1) () lstbox.items(ount) () lstbox.items.ount B 2. Which of the following expressions refers to the contents of the first row of the list box? (A) lstbox.items(0) (B) lstbox.items(1) () lstbox.items.irst () lstbox.items(irst) A 3. Each item in a list box is identified by an index number. he first item in the list is assigned which of the following values as an index? (A) a randomly assigned value (B) 1. () a value initially designated by the programmer () 0 4. he following lines of code display all the items of lstbox. (/) or n As Integer = 1 to lstbox.items.ount lstbox2.items.add(lstbox.items(n)) 5. he number of items in ListBox1 is ListBox1.Items.ount. (/)

15 6. If no item in a list box is selected, the value of lstbox.selectedindex is 0. (/) 7. Which of the statements will unhighlight any highlighted item in lstbox? (A) lstbox.selecteditem = Nothing (B) lstbox.selecteditem = "" () lstbox.selectedindex = 0 () lstbox.selectedindex = A list box named lstbox has its Sorted property set to rue and contains the three items at, og, and Gnu in its Items collection. If the word Elephant is added to the Items collection at run time, what will be its index value? (A) 2 (B) 1 () 3 () 0 A 9. A list box named lstbox has its Sorted property set to alse and contains the three items at, og, and Gnu in its list. If the word Elephant is added to the list at run time, what will be its index value? (A) 2 (B) 1 () 3 () If a program contains procedures for both the lick and oublelick events on a list box and the user double-clicks on the list box, only the lick event will be raised. (/) 11. If a list box has its sorted property set to rue and the list box contains all numbers, then the values in the list box will always be in increasing numerical order. (/) 12. If a list box contains all numbers, then which of the following values can be calculated without using a loop? (A) average value of the numbers (B) largest number () smallest number () number of numbers

16 13. Which of the following is not a type of event that can be raised by user selections of items in a list box? (A) lick event (B) SelectedIndexhanged event () illown event () oublelick event 14. he value of lstbox.items(n) is the nth item in the list box. (/) 15. he sorted property can only be set to rue at design time. (/) 16. he data type is most suited to a flag. (A) Boolean (B) Integer () ecimal () ouble (E) String A 17. A variable that keeps track of whether a certain situation has occurred is called (A) a counter. (B) an accumulator. () a switch. () a flag.

Chapter 6 Repetition. 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops

Chapter 6 Repetition. 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops Chapter 6 Repetition 6.1 Do Loops 6.2 For...Next Loops 6.3 List Boxes and Loops 1 6.1 Do Loops Pretest Form of a Do Loop Posttest Form of a Do Loop 2 Do Loops A loop is one of the most important structures

More information

Chapter 4 Decisions. Section 4.1 Relational and Logical Operators. 1. Asc("A") is 65. What is Asc("C")? (A) 66 (B) 67 (C) 68 (D) "C" B

Chapter 4 Decisions. Section 4.1 Relational and Logical Operators. 1. Asc(A) is 65. What is Asc(C)? (A) 66 (B) 67 (C) 68 (D) C B hapter 4 ecisions Section 4.1 Relational and Logical Operators 1. sc("") is 65. What is sc("")? () 66 () 67 () 68 () "" 2. sc("") is 65. What is displayed by txtox.ext = hr(65) & ""? () () () 656667 ()

More information

Chapter 4: Control structures. Repetition

Chapter 4: Control structures. Repetition Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition

More information

Chapter 4: Control structures

Chapter 4: Control structures Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition

More information

PLD Semester Exam Study Guide Dec. 2018

PLD Semester Exam Study Guide Dec. 2018 Covers material from Chapters 1-8. Semester Exam will be built from these questions and answers, though they will be re-ordered and re-numbered and possibly worded slightly differently than on this study

More information

REPETITION CONTROL STRUCTURE LOGO

REPETITION CONTROL STRUCTURE LOGO CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of

More information

Indicate the answer choice that best completes the statement or answers the question. Enter the appropriate word(s) to complete the statement.

Indicate the answer choice that best completes the statement or answers the question. Enter the appropriate word(s) to complete the statement. 1. C#, C++, C, and Java use the symbol as the logical OR operator. a. $ b. % c. ^ d. 2. errors are relatively easy to locate and correct because the compiler or interpreter you use highlights every error.

More information

Repetition. October 4, Chapter 6 - VB 2005 by Schneider 1

Repetition. October 4, Chapter 6 - VB 2005 by Schneider 1 Repetition October 4, 2006 Chapter 6 - VB 2005 by Schneider 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

More information

Loops / Repetition Statements

Loops / Repetition Statements Loops / Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops C has three kinds of repetition statements: the while loop the for

More information

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points) Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow

More information

*Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN

*Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN

More information

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator. Chapter 5: Looping 5.1 The Increment and Decrement Operators Copyright 2009 Pearson Education, Inc. Copyright Publishing as Pearson 2009 Addison-Wesley Pearson Education, Inc. Publishing as Pearson Addison-Wesley

More information

Chapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed?

Chapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed? Chapter 5: Control Structures II (Repetition) Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct and use countercontrolled, sentinel-controlled,

More information

Lecture 7 Tao Wang 1

Lecture 7 Tao Wang 1 Lecture 7 Tao Wang 1 Objectives In this chapter, you will learn about: Interactive loop break and continue do-while for loop Common programming errors Scientists, Third Edition 2 while Loops while statement

More information

Repetition Structures

Repetition Structures Repetition Structures Chapter 5 Fall 2016, CSUS Introduction to Repetition Structures Chapter 5.1 1 Introduction to Repetition Structures A repetition structure causes a statement or set of statements

More information

Chapter 5: Prefix vs. Postfix 8/19/2018. The Increment and Decrement Operators. Increment and Decrement Operators in Program 5-1

Chapter 5: Prefix vs. Postfix 8/19/2018. The Increment and Decrement Operators. Increment and Decrement Operators in Program 5-1 Chapter 5: Loops and Files The Increment and Decrement Operators ++ is the increment operator. It adds one to a variable. val++; is the same as val = val + 1; ++ can be used before (prefix) or after (postfix)

More information

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators Chapter 5: 5.1 Looping The Increment and Decrement Operators The Increment and Decrement Operators The Increment and Decrement Operators ++ is the increment operator. It adds one to a variable. val++;

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

Control Structures II. Repetition (Loops)

Control Structures II. Repetition (Loops) 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 to 100 The answer will be 1 + 2 + 3 + 4 + 5 + 6 + +

More information

L o o p s. for(initializing expression; control expression; step expression) { one or more statements }

L o o p s. for(initializing expression; control expression; step expression) { one or more statements } L o o p s Objective #1: Explain the importance of loops in programs. In order to write a non trivial computer program, you almost always need to use one or more loops. Loops allow your program to repeat

More information

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Learn about repetition (looping) control structures Explore how to construct and use: o Counter-controlled

More information

All copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva

All copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva All copyrights reserved - KV NAD, Aluva Dinesh Kumar Ram PGT(CS) KV NAD Aluva Overview Looping Introduction While loops Syntax Examples Points to Observe Infinite Loops Examples using while loops do..

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All for repetition statement do while repetition statement switch multiple-selection statement break statement continue statement Logical

More information

Chapter 5: Loops and Files

Chapter 5: Loops and Files Chapter 5: Loops and Files 5.1 The Increment and Decrement Operators The Increment and Decrement Operators ++ is the increment operator. It adds one to a variable. val++; is the same as val = val + 1;

More information

AP Computer Science Principles Programming Question Tips. 1: Which algorithm/code segment achieves some result?

AP Computer Science Principles Programming Question Tips. 1: Which algorithm/code segment achieves some result? AP Computer Science Principles Programming Question Tips Name: Recall that roughly 40 percent of the questions on the AP exam will be programming or algorithm questions. These will often fall into one

More information

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution. Repetition Structures Introduction to Repetition Structures Chapter 5 Spring 2016, CSUS Chapter 5.1 Introduction to Repetition Structures The Problems with Duplicate Code A repetition structure causes

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 5: Control Structures II (Repetition) Why Is Repetition Needed? Repetition allows you to efficiently use variables Can input,

More information

COP 2000 Introduction to Computer Programming Mid-Term Exam Review

COP 2000 Introduction to Computer Programming Mid-Term Exam Review he exam format will be different from the online quizzes. It will be written on the test paper with questions similar to those shown on the following pages. he exam will be closed book, but students can

More information

Loops / Repetition Statements. There are three loop constructs in C. Example 2: Grade of several students. Example 1: Fixing Bad Keyboard Input

Loops / Repetition Statements. There are three loop constructs in C. Example 2: Grade of several students. Example 1: Fixing Bad Keyboard Input Loops / Repetition Statements Repetition s allow us to execute a multiple times Often they are referred to as loops C has three kinds of repetition s: the while loop the for loop the do loop The programmer

More information

Chapter 5: Control Structures II (Repetition)

Chapter 5: Control Structures II (Repetition) Chapter 5: Control Structures II (Repetition) 1 Objectives Learn about repetition (looping) control structures Explore how to construct and use count-controlled, sentinel-controlled, flag-controlled, and

More information

Name Section: M/W T/TH Number Definition Matching (8 Points)

Name Section: M/W T/TH Number Definition Matching (8 Points) Name Section: M/W T/TH Number Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Iteration Counter Event Counter Loop Abstract Step

More information

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition)

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition) C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 5: Control Structures II (Repetition) Objectives In this chapter, you will: Learn about repetition (looping) control structures

More information

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5-1

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5-1 Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5-1 Chapter 6 : (Control Structure- Repetition) Using Decrement or Increment While Loop Do-While Loop FOR Loop Nested Loop

More information

Name Section: M/W T/TH Number Definition Matching (6 Points)

Name Section: M/W T/TH Number Definition Matching (6 Points) Name Section: M/W T/TH Number Definition Matching (6 Points) 1. (6 pts) Match the words with their definitions. Choose the best definition for each word. Event Counter Iteration Counter Loop Flow of Control

More information

Repetition and Loop Statements Chapter 5

Repetition and Loop Statements Chapter 5 Repetition and Loop Statements Chapter 5 1 Chapter Objectives To understand why repetition is an important control structure in programming To learn about loop control variables and the three steps needed

More information

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4. Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations

More information

Structured Programming. Dr. Mohamed Khedr Lecture 9

Structured Programming. Dr. Mohamed Khedr Lecture 9 Structured Programming Dr. Mohamed Khedr http://webmail.aast.edu/~khedr 1 Two Types of Loops count controlled loops repeat a specified number of times event-controlled loops some condition within the loop

More information

Increment and the While. Class 15

Increment and the While. Class 15 Increment and the While Class 15 Increment and Decrement Operators Increment and Decrement Increase or decrease a value by one, respectively. the most common operation in all of programming is to increment

More information

Control Structures. Control Structures Conditional Statements COMPUTER PROGRAMMING. Electrical-Electronics Engineering Dept.

Control Structures. Control Structures Conditional Statements COMPUTER PROGRAMMING. Electrical-Electronics Engineering Dept. EEE-117 COMPUTER PROGRAMMING Control Structures Conditional Statements Today s s Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical

More information

Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Loops and Files Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Chapter Topics o The Increment and Decrement Operators o The while Loop o Shorthand Assignment Operators o The do-while

More information

An Introduction to Programming with C++ Sixth Edition. Chapter 7 The Repetition Structure

An Introduction to Programming with C++ Sixth Edition. Chapter 7 The Repetition Structure An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure Objectives Differentiate between a pretest loop and a posttest loop Include a pretest loop in pseudocode Include

More information

Chapter 6. Repetition Statements. Animated Version The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Chapter 6. Repetition Statements. Animated Version The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 6 Repetition Statements Animated Version required for reproduction or display. Chapter 6-1 Objectives After you have read and studied this chapter, you should be able to Implement repetition control

More information

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite

More information

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 4: Repetition Control Structure

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 4: Repetition Control Structure Learning Objectives At the end of this chapter, student should be able to: Understand the requirement of a loop Understand the Loop Control Variable () Use increment (++) and decrement ( ) operators Program

More information

Islamic University of Gaza Computer Engineering Dept. C++ Programming. For Industrial And Electrical Engineering By Instructor: Ruba A.

Islamic University of Gaza Computer Engineering Dept. C++ Programming. For Industrial And Electrical Engineering By Instructor: Ruba A. Islamic University of Gaza Computer Engineering Dept. C++ Programming For Industrial And Electrical Engineering By Instructor: Ruba A. Salamh Chapter Four: Loops 2 Chapter Goals To implement while, for

More information

Page 1 of 14 Version A Midterm Review 1. The sign means greater than. > =

More information

Java. Programming: Chapter Objectives. Why Is Repetition Needed? Chapter 5: Control Structures II. Program Design Including Data Structures

Java. Programming: Chapter Objectives. Why Is Repetition Needed? Chapter 5: Control Structures II. Program Design Including Data Structures Chapter 5: Control Structures II Java Programming: Program Design Including Data Structures Chapter Objectives Learn about repetition (looping) control structures Explore how to construct and use count-controlled,

More information

Looping. Arizona State University 1

Looping. Arizona State University 1 Looping CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 5 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

A Beginner s Guide to Programming Logic, Introductory. Chapter 5 Looping

A Beginner s Guide to Programming Logic, Introductory. Chapter 5 Looping A Beginner s Guide to Programming Logic, Introductory Chapter 5 Looping Objectives In this chapter, you will learn about: The advantages of looping Using a loop control variable Nested loops Avoiding common

More information

204111: Computer and Programming

204111: Computer and Programming 204111: Computer and Programming Week 4: Control Structures t Monchai Sopitkamon, Ph.D. Overview Types of control structures Using selection structure Using repetition structure Types of control ol structures

More information

Computer Programming I - Unit 5 Lecture page 1 of 14

Computer Programming I - Unit 5 Lecture page 1 of 14 page 1 of 14 I. The while Statement while, for, do Loops Note: Loop - a control structure that causes a sequence of statement(s) to be executed repeatedly. The while statement is one of three looping statements

More information

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible) Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

More information

Dept. of CSE, IIT KGP

Dept. of CSE, IIT KGP Control Flow: Looping CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of Repeated Execution Loop: Group of

More information

Loop Structures. Loop Structures. Algorithm to record 5 TV programmes. Recall Structured Programming..3 basic control structures.

Loop Structures. Loop Structures. Algorithm to record 5 TV programmes. Recall Structured Programming..3 basic control structures. Loop Structures Recall Structured Programming..3 basic control structures Sequence Input -> Process -> Output Selection IF ENDIF SELECT CASE END SELECT Loop Structures DO WHILE LOOP DO LOOP UNTIL FOR NEXT

More information

Repetition CSC 121 Fall 2014 Howard Rosenthal

Repetition CSC 121 Fall 2014 Howard Rosenthal Repetition CSC 121 Fall 2014 Howard Rosenthal Lesson Goals Learn the following three repetition methods, their similarities and differences, and how to avoid common errors when using them: while do-while

More information

Laboratory 5: Implementing Loops and Loop Control Strategies

Laboratory 5: Implementing Loops and Loop Control Strategies Laboratory 5: Implementing Loops and Loop Control Strategies Overview: Objectives: C++ has three control structures that are designed exclusively for iteration: the while, for and do statements. In today's

More information

cs1114 REVIEW of details test closed laptop period

cs1114 REVIEW of details test closed laptop period python details DOES NOT COVER FUNCTIONS!!! This is a sample of some of the things that you are responsible for do not believe that if you know only the things on this test that they will get an A on any

More information

Programming Language. Control Structures: Repetition (while) Eng. Anis Nazer Second Semester

Programming Language. Control Structures: Repetition (while) Eng. Anis Nazer Second Semester Programming Language Control Structures: Repetition (while) Eng. Anis Nazer Second Semester 2017-2018 Repetition statements Control statements change the order which statements are executed Selection :

More information

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points) Name rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables retain their value

More information

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 18 Switch Statement (Contd.) And Introduction to

More information

Chapter 3: Program Statements

Chapter 3: Program Statements Chapter 3: Program Statements Multiple Choice 1 e 2 d 3 e 4 d 5 c 6 a 7 b 8 c 9 d 10 a True/False 1 T 2 F 3 F 4 F 5 T 6 F 7 T 8 T 9 F Short Answer 31 What happens in the MinOfThree program if two or more

More information

Loops / Repetition Statements

Loops / Repetition Statements Loops / Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops C has three kinds of repetition statements: the while loop the for

More information

n Group of statements that are executed repeatedly while some condition remains true

n Group of statements that are executed repeatedly while some condition remains true Looping 1 Loops n Group of statements that are executed repeatedly while some condition remains true n Each execution of the group of statements is called an iteration of the loop 2 Example counter 1,

More information

CSCE150A. Introduction. While Loop. Compound Assignment. For Loop. Loop Design. Nested Loops. Do-While Loop. Programming Tips CSCE150A.

CSCE150A. Introduction. While Loop. Compound Assignment. For Loop. Loop Design. Nested Loops. Do-While Loop. Programming Tips CSCE150A. Chapter 5 While For 1 / 54 Computer Science & Engineering 150A Problem Solving Using Computers Lecture 05 - s Stephen Scott (Adapted from Christopher M. Bourke) Fall 2009 While For 2 / 54 5.1 Repetition

More information

Name SECTION: 12:45 2:20. True or False (12 Points)

Name SECTION: 12:45 2:20. True or False (12 Points) Name SECION: 12:45 2:20 rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables

More information

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 5. Repetition in Programs. Notes. Notes. Notes. Lecture 05 - Loops

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 5. Repetition in Programs. Notes. Notes. Notes. Lecture 05 - Loops Computer Science & Engineering 150A Problem Solving Using Computers Lecture 05 - Loops Stephen Scott (Adapted from Christopher M. Bourke) 1 / 1 Fall 2009 cbourke@cse.unl.edu Chapter 5 5.1 Repetition in

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 10 For Loops and Arrays Outline Problem: How can I perform the same operations a fixed number of times? Considering for loops Performs same operations

More information

Control Statements. Objectives. ELEC 206 Prof. Siripong Potisuk

Control Statements. Objectives. ELEC 206 Prof. Siripong Potisuk Control Statements ELEC 206 Prof. Siripong Potisuk 1 Objectives Learn how to change the flow of execution of a MATLAB program through some kind of a decision-making process within that program The program

More information

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition

Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Java Programming: Guided Learning with Early Objects Chapter 5 Control Structures II: Repetition Learn about repetition (looping) control structures Explore how to construct and use: o Counter-controlled

More information

Iteration Loops. The Do While Loop (Continued) Looping Subtasks

Iteration Loops. The Do While Loop (Continued) Looping Subtasks Iteration s The Do While (Continued) ing Subtasks This section in your book is from pages 2 to. You might think that, since this in the Do While loop section, it only refers to those kinds of loops. This

More information

Chapter 5: Control Structures

Chapter 5: Control Structures Chapter 5: Control Structures In this chapter you will learn about: Sequential structure Selection structure if if else switch Repetition Structure while do while for Continue and break statements S1 2017/18

More information

Principles of Computer Science I

Principles of Computer Science I Principles of Computer Science I Prof. Nadeem Abdul Hamid CSC 120A - Fall 2004 Lecture Unit 7 Review Chapter 4 Boolean data type and operators (&&,,) Selection control flow structure if, if-else, nested

More information

Program Development. Java Program Statements. Design. Requirements. Testing. Implementation

Program Development. Java Program Statements. Design. Requirements. Testing. Implementation Program Development Java Program Statements Selim Aksoy Bilkent University Department of Computer Engineering saksoy@cs.bilkent.edu.tr The creation of software involves four basic activities: establishing

More information

Internet & World Wide Web How to Program, 5/e by Pearson Education, Inc. All Rights Reserved.

Internet & World Wide Web How to Program, 5/e by Pearson Education, Inc. All Rights Reserved. Internet & World Wide Web How to Program, 5/e Sequential execution Execute statements in the order they appear in the code Transfer of control Changing the order in which statements execute All scripts

More information

Repe$$on CSC 121 Fall 2015 Howard Rosenthal

Repe$$on CSC 121 Fall 2015 Howard Rosenthal Repe$$on CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Learn the following three repetition methods, their similarities and differences, and how to avoid common errors when using them: while do-while

More information

Repetition Structures II

Repetition Structures II Lecture 9 Repetition Structures II For and do-while loops CptS 121 Summer 2016 Armen Abnousi Types of Control Structures Sequential All programs that we have written so far The statements inside a pair

More information

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays)

Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) Lecture 2 Arrays, Searching and Sorting (Arrays, multi-dimensional Arrays) In this lecture, you will: Learn about arrays Explore how to declare and manipulate data into arrays Understand the meaning of

More information

Why Is Repetition Needed?

Why Is Repetition Needed? Why Is Repetition Needed? Repetition allows efficient use of variables. It lets you process many values using a small number of variables. For example, to add five numbers: Inefficient way: Declare a variable

More information

Introduction to Computer Science Midterm 3 Fall, Points

Introduction to Computer Science Midterm 3 Fall, Points Introduction to Computer Science Fall, 2001 100 Points Notes 1. Tear off this sheet and use it to keep your answers covered at all times. 2. Turn the exam over and write your name next to the staple. Do

More information

Topics. Chapter 5. Equality Operators

Topics. Chapter 5. Equality Operators Topics Chapter 5 Flow of Control Part 1: Selection Forming Conditions if/ Statements Comparing Floating-Point Numbers Comparing Objects The equals Method String Comparison Methods The Conditional Operator

More information

(Refer Slide Time: 00:26)

(Refer Slide Time: 00:26) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute Technology, Madras Module 07 Lecture 07 Contents Repetitive statements

More information

Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8. Handout 5. Loops.

Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8. Handout 5. Loops. Handout 5 cs180 - Programming Fundamentals Spring 15 Page 1 of 8 Handout 5 Loops. Loops implement repetitive computation, a k a iteration. Java loop statements: while do-while for 1. Start with the while-loop.

More information

Conditionals. For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations:

Conditionals. For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations: Conditionals For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations: final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87; 1. if (num1 < MAX)

More information

LOOPS. Repetition using the while statement

LOOPS. Repetition using the while statement 1 LOOPS Loops are an extremely useful feature in any programming language. They allow you to direct the computer to execute certain statements more than once. In Python, there are two kinds of loops: while

More information

Repetition Structures

Repetition Structures Repetition Structures There are three main structures used in programming: sequential, decision and repetition structures. Sequential structures follow one line of code after another. Decision structures

More information

3 The L oop Control Structure

3 The L oop Control Structure 3 The L oop Control Structure Loops The while Loop Tips and Traps More Operators The for Loop Nesting of Loops Multiple Initialisations in the for Loop The Odd Loop The break Statement The continue Statement

More information

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value 1 Number System Introduction In this chapter, we will study about the number system and number line. We will also learn about the four fundamental operations on whole numbers and their properties. Natural

More information

Conditionals and Loops

Conditionals and Loops Conditionals and Loops Conditionals and Loops Now we will examine programming statements that allow us to: make decisions repeat processing steps in a loop Chapter 5 focuses on: boolean expressions conditional

More information

CS112 Lecture: Loops

CS112 Lecture: Loops CS112 Lecture: Loops Objectives: Last revised 3/11/08 1. To introduce some while loop patterns 2. To introduce and motivate the java do.. while loop 3. To review the general form of the java for loop.

More information

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 06 / 04 / 2015 Instructor: Michael Eckmann Today s Topics Questions / comments? Calling methods (noting parameter(s) and their types, as well as the return type)

More information

CHAPTER 5 FLOW OF CONTROL

CHAPTER 5 FLOW OF CONTROL CHAPTER 5 FLOW OF CONTROL PROGRAMMING CONSTRUCTS - In a program, statements may be executed sequentially, selectively or iteratively. - Every programming language provides constructs to support sequence,

More information

Chapter 3 Structured Program Development

Chapter 3 Structured Program Development 1 Chapter 3 Structured Program Development Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 3 - Structured Program Development Outline 3.1 Introduction

More information

STUDENT LESSON A12 Iterations

STUDENT LESSON A12 Iterations STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of

More information

Subject: Computer Science

Subject: Computer Science Subject: Computer Science Topic: Data Types, Variables & Operators 1 Write a program to print HELLO WORLD on screen. 2 Write a program to display output using a single cout statement. 3 Write a program

More information

Day06 A. Young W. Lim Mon. Young W. Lim Day06 A Mon 1 / 16

Day06 A. Young W. Lim Mon. Young W. Lim Day06 A Mon 1 / 16 Day06 A Young W. Lim 2017-09-18 Mon Young W. Lim Day06 A 2017-09-18 Mon 1 / 16 Outline 1 Based on 2 Introduction C Program Control Young W. Lim Day06 A 2017-09-18 Mon 2 / 16 Based on "C How to Program",

More information

CS110D: PROGRAMMING LANGUAGE I

CS110D: PROGRAMMING LANGUAGE I CS110D: PROGRAMMING LANGUAGE I Computer Science department Lecture 5&6: Loops Lecture Contents Why loops?? While loops for loops do while loops Nested control structures Motivation Suppose that you need

More information

Lesson 6A Loops. By John B. Owen All rights reserved 2011, revised 2014

Lesson 6A Loops. By John B. Owen All rights reserved 2011, revised 2014 Lesson 6A Loops By John B. Owen All rights reserved 2011, revised 2014 Topic List Objectives Loop structure 4 parts Three loop styles Example of a while loop Example of a do while loop Comparison while

More information

CMPT 102 Introduction to Scientific Computer Programming

CMPT 102 Introduction to Scientific Computer Programming CMP 102 Introduction to Scientific Computer Programming Control Structures while Loops continue; and break; statements Janice Regan, CMP 102, Sept. 2006 0 Control Structures hree methods of processing

More information