question on this java code segment -


the following code claimed use loop flag repeat input until valid int obtained.

 {         try   {     // attempt convert string int     n = integer.parseint( s );     goodinput = true;   }   catch ( numberformatexception nfe )   {     s = joptionpane.showinputdialog( null,             s + " not integer. enter integer" );   } } while ( !goodinput ); 

i little confusing logic here. if integer.parseint works fine, or there no exception occuring, "goodinput" assigned "true" @ line of

 goodinput = true; 

then !goodinput evaluated false, while loop continue again. seems me contradicts designed logic, i.e., while loop should stop after performing correct parse operation. wrong analysis above.

do { } while(x); loops while x == true, i.e. until x == false.

therefore, do { } while(!x); loops while x == false, i.e. until x true.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -