Hi all 

 

I am emcounterig problems when trying to convert the for loop into a while 
loop. 

The following is the program code of the for loop, i have tried many statements 
but without success. 

 

Your help will be really appreciated. 

Many thanks

 

import javax.swing.JOptionPane;
/**
 *
 * @author Compuline
 */
public class OwnWhile {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
          String names 
[]={"Beah","Bianca","Lance","Belle","Nico","Yza","Gem","Ethan"};

              

          String searchName = JOptionPane.showInputDialog("Enter either \"Yza\" 
or \"noname\"!");

       

         // Declare and initialize boolean primitive type variable calld 
foundName.
         boolean foundName =false;

          

          // my while loop code

          int i = 0;
          while (i<names.length){                                    
            i++;
            if (names [i].equals(searchName)){
                foundName = true;
            }
         }

          
        

        // for loop code      
        //for (int i=0; i<names.length; i++){
        //    if (names [i ].equals(searchName)){
        //        foundName =true;
        //        break;
        //    }
        // }
            
            // Display the result
        if (foundName)
            JOptionPane.showMessageDialog(null, searchName + " is found!");
        else
            JOptionPane.showMessageDialog(null, searchName + " is not found!");

 


        }
    }


 

_________________________________________________________________
More than messages–check out the rest of the Windows Live™.
http://www.microsoft.com/windows/windowslive/
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to