• 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

Assertions

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


with assertion enabled.the above programs gives 012.That part i got it.But with assertion disabled how it displays infinite times.When it comes to execute
while 3<3 condn it returns false.I thought with assertion disabled also it will come out of loop.Please clear my doubt.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shiva Mohan:
...with assertion disabled how it displays infinite times. When it comes to execute while 3<3 condn it returns false...


With assertions disabled, the expression following "assert" is not evaluated. So in this code, i1 is never incremented.

It's not that i1<3 returns false when i1 is 3. It's that i1 remains at zero.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this with assertions enabled, and with assertions disabled...
 
Shiva Mohan
Ranch Hand
Posts: 486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sir! Excellent coding explanation.Thank you very much.
Without enabled assertions,it displayed all x value 0.(but i don't know why that increment doesn't happen)
does that mean we used inappropriate use of assertions.
I mean "Do not use assert expression that can cause side effects".
 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

.(but i don't know why that increment doesn't happen)
does that mean we used inappropriate use of assertions.
I mean "Do not use assert expression that can cause side effects".



Exactly. Use assertions only for evaluating conditions that you know should never arise. In other words, the assertion code should not modify the data and behaviour of your program in any way. The compiler will not complain, but it is a bad programming practice and misuse of assertions.
 
reply
    Bookmark Topic Watch Topic
  • New Topic