Chapter 5

Created by Tatiyana Tongbua

++ & --
change operands one by one

1/22

TermDefinition
++ & --
change operands one by one
Decrement
decrease by value
++
unary, adds one value, operates in prefix or postfix
num++ vs ++num
num++ -postfix -returns original then increments ++num -prefix -increases values and returns
while
term image
-condition and statement/block that is repeated if condition is true -unlimited number of statements (have to be in brackets) -FALSE: semicolon(;) after test expression
while vs do
-while: pretest -do: posttest
do-while
-statement is repeated at least once
sentinel
-special value -marks the end of a list of values -signals end of sequence/to terminate -IMAGE: -1 is the sentinel
definition image
for
-initialize, test, and update -initialization executes only once -TRUE: initialization may be omitted if no initialization is required -can define a variable in initialization
accumulator
-variable that keeps a running total of data values -variable that stores a running total -accumulates - repeatedly applies an operation
counter vs accumulator
counter - integer that increments by fixed amount (1) accumulator - holds any type of value, updated by any operation
Best uses for loops
-for: fixed number iterations(start & end known), counting loops -while: unknown number of iterations, event driven (input) -dowhile: when body must execute at least once, validation loops (keeps asking for input until valid)
fstream
-header file -allows file use
to use output file
-create file stream object that references the file -open the file -NOT: make sure file already exists
--
unary, subtracts, must have lvalue(variable) as operand, prefix or postifx
if nothing within while loop causes condition to become false
infinite loop
loop control variable
variable that controls the # of times a loop iterates
counter
variable that is regularly incremented/decremented each loop iteration
nested loop
inner loop goes through all its iterations for each iteration of outer loop
break
causes loop to terminate early
while has no braces around body
loop body contains just one statement
read data from file
-file must already exist, program must define a reference, open file