Download presentation
Presentation is loading. Please wait.
1
Patterns to KNOW
2
Sentinel Logic Priming input
While input does NOT meet sentinel condition Do processing of valid input Input again
3
Input (data) validation
Very similar to sentinel logic The difference is in the meaning – “loop while data is BAD”, where Sentinel Logic is “loop while data is GOOD” Priming input While input does NOT meet valid data criteria Report invalid data to user Input data again
4
Flags – ANY pattern Set flag to False
Code to provide data to check (loop or series of if statements) If condition to flag is detected Set flag to True After all data is processed If flag is True, at least one value with condition has been seen Else no value with condition has been seen
5
Flags – ALL pattern Set flag to True
Code to process data (while or series of if statements) If condition to check does NOT hold, set flag to False (note that this if does NOT have an else!) After all data is processed If flag is True, the condition was True for all values seen Else at least one item with the condition False has been seen
6
Accumulating Initialize the accumulator variable to the “empty” state for its data type, that is 0 or 0.0 for numbers, ‘’ (empty string) for strings, [] for lists, etc. Process all the data as needed in loops, etc. Use an accumulating statement variable operator= expression, such as x += 1, sentence += word, z -= num, datalist += item
7
Previous - Current Obtain the first piece of data, call it previous
For all the other items of data get another item of data, call it current process data as needed, using both pieces of data prev and curr then move current to previous (previous = current)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.