Chapter 5 Flashcards
(32 cards)
to increase a value by one
increment
to decrease a value by one
decrement
operator is placed after the variable; matters when using operator in expression (will change value after expression executes)
postfix mode
operator is placed before the variable; matters when using operator in expression (will change value before expression executes)
prefix mode
consists of key word for loop followed by an exp enclosed in () / braces for body of loop
loop header
exp in () is tested; if it’s true, statement is executed; then exp is tested again; if true, statement is executed; cycle repeates until exp is false; is a pretest loop
while loop
tests its exp before each iteration; loop will never iterate if test exp is false to start
pretest loop
continues to repeat until program is interrupted; possible to create by accident by placing semicolon at end of loop header (disconnects body from loop) or by not updating test condition
infinite loop
process of inspecting data given to program by user and deting if it’s valid; while loop is good for this
input validation
read operation that takes place just before loop; provides the first value for the loop to test; subsequent values are obtained by the loop
priming read
variable that is regularly updated in each iteration of the loop; keeps track of the number of iterations loop has performed; set variable equal to starting value and create loop where variable is than another value and update the variable
counter
looks like an inverted while loop; must be terminated w/a semicolon; always performs at least one iteration, even if exp is false to start; is a post-test loop; should use when you want to make sure loop executes at least once (as in w/ menus); while cond is located at closing brace
do-while loop
doesn’t test exp until it has completed an iteration
post-test loop
allows user to decide number of iterations (via sentinel value or entering number into control variable)
user-controlled loop
type of loop specifically designed to initialize, test, and update a counter variable; first step is initialization exp, then second exp is tested (controls execution of loop and will repeat body of loop as long as exp is true), then third exp updates counter at end of each iteration; is a pretest loop
for loop
sum of #s that accumulates with each iteration of a loop; requires 1) loop that reads in each # in the series and 2) variable that accumulates total # of #s as they are read
running total
variable used to accumulate the total #s
accumulator
special value that can’t be mistaken as a member of the list and signals that there are no more values to be entered; when user enters it, loop terminates (set while loop != to sentinel value); will not be included in running total
sentinel
file data is written to; program stores __ in it;
output file
file that data is read from; when a piece of data is read from a file, it’s copied from file into a variable in RAM; prgm gets __ from it
input file
1) file must be opened
2) file is processed
3) file must be closed
steps to using files
accesses data from beginning of file to end of file; you have to read all data that comes before piece of data you want to access
sequential access (file)
can jump directly to any piece of data in file w/out reading data that comes before it
random / direct access (file)
with what files on disk are identified by
file name