The Java while loop is used to iterate a part of the program several times. If the number of iteration is not fixed, it is recommended to use while loop.
While loop starts with the checking of condition. If it evaluated to true, then the loop body statements are executed otherwise first statement following the loop is executed. For this reason it is also called Entry control loop.
Once the condition is evaluated to true, the statements in the loop body are executed. Normally the statements contain an update value for the variable being processed for the next iteration.
When the condition becomes false, the loop terminates which marks the end of its life cycle.
Infinite while loop
Syntax
while(true){
//code to be executed
}
Program
publicclass infinite_while
{
publicstaticvoid main(String args[])
{
while(true)
{
System.out.println("Infinite while loop");
}
}
}
Output
Infinite while loop
Infinite while loop
Infinite while loop
Infinite while loop
Infinite while loop
Infinite while loop
Infinite while loop
Infinite while loop
Explanation
If you pass true in the while loop, it will be infinitive while loop.
Here, condition is always true so program runs continuously. You have to press ctrl+c to stop the program.
In this article we view three key (and interrelated) topics that make it all possible: the CLR, CTS, and CLS . Common Language Runtime From a programmer’s point of view, .NET can be understood as a runtime environment and a comprehensive base class library. The runtime layer is properly referred to as the Common Language Runtime , or CLR. The primary role of the CLR is to locate, load, and manage .NET objects on your behalf. The CLR also takes care of a number of low-level details such as memory management, application hosting, coordinating threads, and performing basic security checks (among other low-level details). Common Type System Another building block of the .NET platform is the Common Type System , or CTS. The CTS specification fully describes all possible data types and all programming constructs supported by the runtime, specifies how these entities can interact with each other, and details how they are represented in the .NET metadata format. Common Languag...
1. Download JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html 2. Install the JDK. 3. Go to path C:\Program Files (x86)\Java\jdk1.8.0_131\bin in your PC and copy it. 4. Now go to control panel 5. Click on system 6. Click on advance system settings 7. Click on environment variables 8. Click on new and name it as path and copy path which is in your pc as shown above in red colour 9. Click on OK 10. Now open CMD and type javac and press enter if it shows messy long list then congratulation java is installed in your PC. 11. Now go to next article for Hell...
Methods appear inside class bodies. They contain local variable declarations and other Java statements that are executed when the method is invoked. Methods may return a value to the caller. They always specify a return type, which can be a primitive type, a reference type, or the type void , which indicates no returned value. Methods may take arguments, which are values supplied by the caller of the method. Lets see example: Program class multiply { int num1; int num2; int mul(int x,int y) { int result; num1 = x; num2 = y; result = num1*num2; return result; } } public class Main { public static void main (String[] args) { multiply m = new multiply(); System.out.println("multiplication of 3 and 5 is " + m.mul(3,5)); } } Run Output multiplication of 3 and 5 is 15 Explanation In this example, the class multiply defines a method, mul() , that takes as argu...
Comments
Post a Comment