You are here

Human Example of the while Loop

5 February, 2015 - 11:20

Consider the following one-way conversation from a mother to her child.

Child: The child says nothing, but mother knows the child had Cheerios for breakfast and history tells us that the child most likely spilled some Cheerios on the foor.

Mother says: "While it is true that you see (As long as you can see) a Cheerio on foor, pick it up and put it in the garbage."

Note: All of the elements are present to determine the action (or fow) that the child will be doing (in this case repeating). Because the question (can you see a Cheerios) has only two possible answers (true or false) the action will continue while there are Cheerios on the foor. Either the child 1) never picks up a Cheerio because they never spilled any or 2) picks up a Cheerio and keeps picking up Cheerios one at a time while he can see a Cheerio on the foor (that is until they are all picked up).