Simple Java While Loop Example

Simple Java While Loop Example

Java While Loop is used to iterate a program code for non-specified number of times.

Syntax:

 while(condition)  
 {  
 //execute this code if condition is true  
 }  

Example:


 

public class WhileLoop {
    public static void main(String args[])
    {
   int num=1;
    while (num<=9)
    {
    System.out.println("Number is  "+num);
   
   num++;
    }
        
        
    }
    
    
}

Output:


 Number is 1  
 Number is 2  
 Number is 3  
 Number is 4  
 Number is 5  
 Number is 6  
 Number is 7  
 Number is 8  
 Number is 9  
 BUILD SUCCESSFUL (total time: 0 seconds)  

Java Infinitive While Loop

If we replace the condition with boolean true,while loop becomes infinitive while loop.


Syntax:


 while(true)  
 {  
 //execute this code here  
 }  

Example:


 
public class InfinitiveLoop
 { 
public static void main(String args[]) 
{ 
while (true) 
{ 
System.out.println("Infinitive Java While Loop");
 }
 } 
}


Output:


 Infinitive Java While Loop  
 Infinitive Java While Loop  
 Infinitive Java While Loop  
 Infinitive Java While Loop  
 Infinitive Java While Loop  
 Infinitive Java While Loop  
 Infinitive Java While Loop  
 Infinitive Java While Loop  
 Infinitive Java While LoopBUILD STOPPED (total time: 1 second)  

COMMENTS

Name

android android Apps android emulators antivirus blogger bluestack Break Statement in Java constructors download downloader drivers emulators java java control statements java do-while loop java for loop java infinitive do-while loop java system methods java tutorials Java While Loop java.awt java.swing javalookandfeel javascript JButton JCheckBox JColorChooser JComboBox JDialog JFileChooser JFrame JLayeredPane JList JMenuBar joomla JOptionPane JPanel JPasswordField JPopupMenu JProgressBar JRadioButton JScrollBar JSlider JSpinner JTabbedPane JTable JTextArea JTextField JToolBar mysql php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
false
ltr
item
Java Codes: Simple Java While Loop Example
Simple Java While Loop Example
Simple Java While Loop Example
Java Codes
http://www.download-all.net/2017/01/simple-java-while-loop-example.html
http://www.download-all.net/
http://www.download-all.net/
http://www.download-all.net/2017/01/simple-java-while-loop-example.html
true
7826648292785071009
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy