1/53
TERMINOLOGIES ONLY
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Loop
A part of a program that repeats
Loop body
Contains the statements to be repeated
Looping Statement, The Condition, Initializing Statement, Statement that allows the condition to become false
4 Elements of a Loop Structure
Looping statement
while, for, and do while
Initializing Statement
Placed before the condition to ensure correct loop execution the first time the condition is evaluated
Statement that allows the condition to become false
ex. counter++, counter--, get a new input(for sentinel-controlled loop)
note: if one of these is missing, the loop will not work properly
Pre-test loop
The condition is tested first, if it is true the body of the loop is executed. This process repeats until the condition becomes false. Then the next statement after the loop is executed. Examples of _______________ are while and for loop
Post-test loop
The body of the loop is executed first before the condition is tested.
This process repeats until the condition becomes false.
Then the next statement after the loop is executed.
In this type of loop the body of the loop is executed at least once.
The do while is an example of such loop
Flowchart of Pre-test Loop
This flow chart is an example of what type of loop?
Flowchart of Post-test Loop
This flow chart is an example of what type of loop?
Iteration
each repetition in a loop. If the statements inside the loop are repeated 10 times then there are 10 __________
Counter-controlled loops
Type of loop where the number of iteration is known before the loop is executed. It uses a counter variable. its repetition is managed by a loop control variable whose value represent a count.
The While Loop
It has 2 important parts: (1) an expression that is tested for a true or false value, and (2) a statement or block that is repeated as long as the expression is true.
Prior
We use a counter-controlled loop when we can determine _______ to loop execution exactly how many iterations will be needed. This number should appear as the final value
The For Loop
Ideal for situations that require a counter (fixed iteration). ______________ can be used to count up or down by any interval.
Initialization, Condition, Statement/s, Update
For For Loop: First, the ___________ is executed. Then, the _________ is tested, if it is true, the __________ inside the loop are executed, and then the __________. Until the loop ends.
The Do While Loop
First, the initialization is executed. Then, the statement/s inside the loop are executed, and then the update. Then, the condition is tested, if it is true,
Sentinel
Data values used to signal either the start or end of a data series. Not part of the data series.
Sentinel Value
must be selected so as not to conflict with legitimate data values.
Break
forces an immediate break or exit from while, for, and do_while statements
Continue
When _________ is encountered in a loop, the next iteration of the loop will immediately begin
Loops
can be used to validate your inputs. If an invalid data is entered, a ________ can be used to ask the user to re-enter a data until a valid value is entered.
Validation Loop
In creating a ___________, the condition is always opposite to the valid values.
Flag-Controlled Loop
Uses a boolean variable (called a flag variable) to control the logical flow of the program.
True, False
set the boolean variable to ___________ before the loop and reset it to ________ when you need to exit the loop.
Initialize, Test, Update
Flag-Controlled Loop Design Rules:
1. _________ a flag (to true or false). Make sure that you use a meaningful name for the flag
2. ______ the flag in the loop test expression.
3. ________: A condition in the loop body that changes the value of the flag (to false or true)
Nested Loop
If a loop exists inside the body of another loop, it's called a _________.
Loop Condition or Condition
The logical expression is called a ____________ or simply a ___________.
Statement
Is called the body of the loop
Parentheses
The ____________ around the logical expression are part of the syntax.
Entry Condition
The logical expression provides an ___________.
Infinite Loop
A loop that continues to execute endlessly is called an ___________.
Loop Control Variable (LCV)
The variable i (Line 2) in the expression is called the______________. The expression checks whether a variable(s), called the ____________, satisfies certain conditions.
Sentinel
You might not know exactly how many times a set of statements needs to be executed, but you do know that the statements need to be executed until a special value is met. This special value is called a __________.
Sentinel-Controlled While Loop
The while loop continues to execute as long as the program has not read the sentinel. Such a while loop is called a __________________________.
Flag Variable
The variable, such as found, which is used to control the execution of the while loop, is called a ________.
EOF (End Of File)-controlled while loop
The programmer sometimes does not know what the sentinel is. In such situations, you can use an ___________________.
For Loop Controls
The initial statement usually initializes a variable (called the _______________, or indexed, variable).
Counted or Indexed
The for loop is typically called a __________ or ________ for loop.
Do While Loop
The _______ is useful when it does not make sense to check a condition until after the action occurs.
Software Patch
A __________ is a piece of code written on top of an existing piece of code and intended to remedy a deficiency in the original code.
While, For, Do While
Java has three looping (repetition) structures: ______, _______, _______
Reserved Word
In Java, while is a _____________.
Parentheses
In a while statement, the ___________ around the logical expression, the loop condition, are required; they mark the beginning and end of the expression.
Counter
A counter-controlled while loop uses a _________ to control the loop.
False
The body of the while loop typically contains statement(s) that eventually set the expression to _______ to terminate the loop.
Initialize
In a counter-controlled while loop, you must __________ the counter before the loop, and the body of the loop must contain a statement that changes the value of the counter variable.
Similar, Different
The sentinel must be ______, yet ________ from all the data items.
While, For, Do While
Java Reserved Words
Simplifies
A for loop __________the writing of a counter-controlled while loop.
Semicolon
If you put a ____________ at the end of the for loop (before the body of the for loop), the action of the for loop is empty.
Terminates
Executing a break statement in the body of a loop immediately ___________ the loop.
Might Not Execute
When a continue statement executes in a while or do...while loop, the update statement in the body of the loop ______________
Next Statement
After a continue statement executes in a for loop, the update statement is the ________________ executed.