SD card works in setup but not in loop

You have an incomplete sketch. What are the sources you copied?