• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt in Regex (KnB book)

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another point observed in the KnB book is that for almost all the examples the authors have used the following code...

Pattern p = Pattern.compile("aba");
Matcher m = p.matcher("ababababababa");
boolean b = false;

while (b = m.find)
{ System.out.print("Answers"); }

Now can anyone please help me out with the value of using the "while (b = m.find)" option?
I find it works the same with out the boolean too "while (m.find)"
Is it actually necessary or am i missing something here?

Thanks
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Now can anyone please help me out with the value of using the "while (b = m.find)" option?
I find it works the same with out the boolean too "while (m.find)"
Is it actually necessary or am i missing something here?



Of Course you are right....You are just using a short hand option...whether you use b = m.find or just use m.find...both evaluate to a boolean value...and as far as its a boolean...all goes well with while loop in this example...

thanks,
Megha
 
reply
    Bookmark Topic Watch Topic
  • New Topic