I'd like to know the difference between the following two codes using while and for loop in each.
I want to pop elements of the list sandwich_orders
into the list of finished_sandwich
. it seems to work with while loop but not with for loop. What mistake did I make?
sandwich_orders = ['chicken sandwich', 'beef sandwich', 'avocado sandwich', 'pork sandwich']
finished_sandwich = []
while sandwich_orders:
cur_sandwich = sandwich_orders.pop()
finished_sandwich.append(cur_sandwich)
print (finished_sandwich)
for cur_sandwich in sandwich_orders:
cur_sandwich = sandwich_orders.pop()
finished_sandwich.append(cur_sandwich)
print (finished_sandwich)