As we are discussed in the previous file, the java while loop is used to repeat the part of the program many times. If the number of repetitions is not fixed, then the while loop is used.
1. Welcome to Ducat India
Language | Industrial Training | Digital Marketing | Web Technology | Testing+ | Database | Networking |
Mobile Application | ERP | Graphic | Big Data | Cloud Computing
Apply Now
Call us:
70-70-90-50-90
www.ducatindia.com
2. Java While Loop
As we are discussed in previous file, java while
loop is used to repeat the part of the program
many times. If the number of repetition is not
fixed, then while loop is use.
Syntax
while (condition)
{
statements (s)
}
Flowchart
3. In above flowchart shows, firstly, condition is evaluated and if condition is true then
statement in while loop is executed. If condition is false, then it comes to out of the loop and
go to next statement.
Example
public class whileLoopExample{
public static void main(String[]args){
int i=1;
while(i<=15){
System.out.println(i);
i++;
}
}
}
5. Infinitive While Loop
In while loop if we pass true it will be infinitive while loop.
Syntax
while (true){
statement(s);
}
Example
class WhileInfinitiveExample2 {
public static void main(String[] args) {
while(true){
System.out.println(“infinitive while loop”);
}
}
}
6. Output
infinitive while loop
infinitive while loop
infinitive while loop
infinitive while loop
infinitive while loop
ctrl+c
Ctrl+c is use to exit the program