I need help understanding this logic:

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

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.