hello quizlet
Home
Subjects
Expert solutions
Create
Study sets, textbooks, questions
Log in
Sign up
Upgrade to remove ads
Only $35.99/year
EX2: WK5 Object Oriented Programming
Flashcards
Learn
Test
Match
Flashcards
Learn
Test
Match
Terms in this set (24)
Loop
A structure that allows repeated execution of a block of statements
Loop body
- A block of statements - Executed repeatedly
Iteration
- One execution of any loop
Definite or Counted loop
- Loop that executes specific number of times
Indefinite loop
- Loop executes undetermined number of times
while loop
■ The loop-controlling Boolean expression is the first statement
- Executes a body of statements continually ■ As long as the Boolean expression that controls entry into the loop continues to be true - Consists of: ■ The keyword X ■ Followed by a Boolean expression within parentheses ■ Followed by the body of the loop; can be a single statement or a block of statements surrounded by curly braces
do...while loop
■ The loop-controlling Boolean expression is the last statement
■ Loop will execute at least once
Definite loop
- Performs a task a predetermined number of times - Also called a counted loop
Infinite loop
- A loop that never ends - Can result from a mistake in the while loop - Do not write intentionally
Suspect an X when: - The same output is displayed repeatedly - The screen remains idle for an extended period of time
Accumulating
- Repeatedly increasing a value by some amount
+=
-=
*=
/=
%=
add and assign operator
subtract and assign operator
multiply and assign operator
divide and assign operator
remainder and assign operator
Prefix increment operator
++someValue
■ The result is calculated and stored ■ Then the variable is used
- Use only with variables - Unary operators ■ Use with one value - Increase a variable's value by 1 ■ No difference between operators (unless other operations are in the same expression)
postfix increment operator
someValue++
■ The variable is used ■ Then the result is calculated and stored
- Use only with variables - Unary operators ■ Use with one value - Increase a variable's value by 1 ■ No difference between operators (unless other operations are in the same expression)
for loop
■ A concise format in which to execute loops -Used when a definitenumber of loop iterations is required - One convenient statement indicates: ■ The starting value for the loop control variable ■ The test condition that controls loop entry ■ The expression that alters the loop control variable
Creating a for Loop
■ Other uses for the three sections of a X - Initialization of more than one variable ■ Place commas between separate statements - Performance of more than one test using AND or OR operators - Decrementing or performance of some other task - Altering more than one value ■ You can leave one or more portions of a X empty ■ Two semicolons are still required as placeholders ■ Use the same loop control variable in all three parts of a for statement ■ To pause a program: - Use the X that contains no body (do-nothingloop) for(x = 0; x < 100000; ++x); - Or use the built-in sleep() method
do...while loop
- A posttest loop - Checks the value of the loop control variable ■ At the bottom of the loop ■ After one repetition has occurred - Performs a task at least one time - You are never required to use this type of loop - Use curly braces to block the statement ■ Even with a single statement
Inner loop
An X must be entirely contained in an outer loop - Loops can never overlap
Outer loop
An inner loop must be entirely contained in an X - Loops can never overlap
Improving Loop Performance
■ Make sure a loop does not include unnecessary operations or statements - While(x < a+b) ■ Consider the order of evaluation for short-circuit operators - AND & OR uses short circuit expressions While(requestedNum > LIMIT || requestedNum <0) ■ Make comparisons to zero (0) - for(int x = 0; x <= REPEAT; ++x) vs. for(int x = REPEAT; x >= 0; --x) ■ Employ loop fusion to combine loops - A technique of combining two loops into one - Will not work in every situation - Improve performance if two methods does not depend on each other
Comparing to Zero
Making a comparison to X is faster than making a comparison to any other value ■ To improve loop performance, compare the loop control variable to X
Arrays
■ An X is a list of contiguous values in computer memory ■ An X has a specified size and does not change ■ Each item in an X is called an element ■ Each element in the X have the same data type ■ Each element can be accessed using a subscript ■ The subscript values are 0 to one number less than the size of the X
Initializing an Array 1/3
■ Array names: - Represent computer memory addresses - Contain references ■ When you declare an array name: - No computer memory address is assigned - The array has the special value null ■ Unicode value '\u0000'
Initializing an Array 2/3
■ Use the keyword new to define an array - The array name acquires the actual memory address value ■ int[] someNums = new int[10];
- Each element of someNums has a value of 0 ■ char array elements - Assigned '\u0000' ■ boolean array elements - Automatically assigned the value false ■ Strings and arrays of objects - Assigned null by default
Initializing an Array 3/3
■ Assign nondefault values to array elements upon creation int[] tenMult = {10, 20, 30, 40, 50, 60}; ■ An initialization list initializes an array - Values are separated by commas and enclosed within curly braces ■ Populating an array - Providing values for all the elements in an array ■ You can use the for loop to assign values to an array ■ In java, you cannot directly initialize part of an array - if there are 5 elements, you have initialize all 5 elements or no elements
Sets found in the same folder
EX2: WK7 Object Oriented Programming
25 terms
EX2: WK6 Object Oriented Programming
21 terms
EX2: WK8 Object Oriented Programming
25 terms
EX1: WK1 Programming Basics
23 terms
Other sets by this creator
EX1: WK4 Object Oriented Programming
15 terms
EX1: WK3 Object Oriented Programming
17 terms
EX1: WK2 Object Oriented Programming
34 terms
EX2 Ch 14 Installation & Operations
7 terms
Verified questions
physics
A spherical mirror at an amusement park has a radius of 10 m. If it forms an image that has a lateral magnification of +2.0, what are the object and image distances?
physics
A dielectric is pulled out from between the plates of a capacitor which remains connected to a battery. What changes occur to the potential difference? Explain your answer.
engineering
The combustion of a hydrocarbon fuel with air results in a mixture of products of combustion having the composition on a volume basis as follows: 4.89 percent carbon dioxide, 6.50 percent water vapor, 12.20 percent oxygen, and 76.41 percent nitrogen. Determine the average molar mass of the mixture, the average specific heat at constant pressure of the mixture at 600 K in $\mathrm{kJ} / \mathrm{kmol} \cdot \mathrm{K},$ and the partial pressure of the water vapor in the mixture for a mixture pressure of 200 kPa.
chemistry
Identify the atom with the following ground-state electron configuration:
Recommended textbook solutions
Information Technology Project Management: Providing Measurable Organizational Value
5th Edition
•
ISBN: 9781118911013
(2 more)
Jack T. Marchewka
346 solutions
Information Technology Project Management: Providing Measurable Organizational Value
5th Edition
•
ISBN: 9781118911013
(2 more)
Jack T. Marchewka
346 solutions
Starting Out with C++ from Control Structures to Objects
8th Edition
•
ISBN: 9780133769395
(10 more)
Godfrey Muganda, Judy Walters, Tony Gaddis
1,294 solutions
Computer Organization and Design MIPS Edition: The Hardware/Software Interface
5th Edition
•
ISBN: 9780124077263
(5 more)
David A. Patterson, John L. Hennessy
220 solutions
Other Quizlet sets
chapter 7 programming terms
16 terms
Chapter 6 Key Term
32 terms
CH. 5 Looping
49 terms