I don't think you want to use break here. Break won't just cause the rest of that iteration of the loop to stop executing, but will also stop from going through the rest of the setup elements. You probably want to remove the break, and change the if condition to: if(chapter != nil) .