• Post Reply Bookmark Topic Watch Topic
  • New Topic

exiting for loop  RSS feed

 
Kip Bodey
Ranch Hand
Posts: 43
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to check my array for a title, if the title is there i want to call a method, if the title is not there i want an error message. im not sure how to get this. i think my code would work if it didnt always finish the method. for example if true the method stops and does run whats after the for loop. but that isnt happening. any help please?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can just return from the method inside the conditional (if) clause.
 
Kip Bodey
Ranch Hand
Posts: 43
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you know ive spent about 4 hours on that. like i knew i needed to do that but i thought return had to have a value, well thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


A return statement in a void method doesn't need a value because the method is declared to return no value. If the method was declared to return a value, then the return must specify what that value is.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!