I need help understanding this logic:

itemList = call Function getItemListFromUser
for (each item in itemsList)
listItemPrice = get price for item
totalOrder = totalOrder + listItemPrice

2 Years
Discussion Span
Last Post by overwraith

Sounds like what happens at a cash register all the time. The checker scans items, the price is looked up and the final tally is the bill.


Yeah, that's just an accumulating loop, it's pretty simple really. You don't have whitespace in the right places so the foreach loop doesn't look intuitive, but you should have no trouble understanding this. The two statements below the foreach loop in your pseudo code would essentially be in brackets in a full up programming languages so that they are grouped to run inside the loop. Perhaps you don't understand how functions work? Functions can and do return objects and collections. After this pseudo code you would typically have a printing statement which prints the total, or you would set a variable for the total whether it be an object unto it's self, or simply a variable to hold the currency value.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.