Missing semicolon

My code throws an error (“missing ;”) and I don’t know why…

  int i =0;
  while (i < books.size()){
    for(i<books.size(); i++){
}
}

Are you trying to do a for loop, or a while loop? You probably want a for loop, and not a while loop.

for( int i = 0; i < books.size(); i++ ) {
  // Do something in here with books[i].
}
1 Like

Thanks! I got it to work :slight_smile: I do actually want a while loop and I managed to get it to work with

 int i =0;
  while (i < books.size()){
}
1 Like

Okay! Just don’t forget to increment i inside your while loop! :wink:

2 Likes