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.
Like any programming language, C# defines keywords for fundamental data types, which are used to represent local variables, class data member variables, method return values, and parameters. Unlike other programming languages, however, these keywords are much more than simple compiler- recognized tokens. Rather, the C# data type keywords are actually shorthand notations for full-blown types in the System namespace. Table lists each system data type, its range, the corresponding C# keyword, and the type’s compliance with the common language specification (CLS). C# keyword System type Range Meaning CLS complaint? bool System.Boolean true or false Represents truth or falsity Yes sbyte System.SByte -128 to 127 signed 8-bit number No byte System.Byte 0 to 255 Unsigned 8-bit ...
In this article we will see this keyword in Java. this keyword in Java this keyword in Java is a special keyword which can be used to represent current object or instance of any class in Java. “this” keyword can also call constructor of same class in Java and used to call overloaded constructor. In this article we will see how to use this keyword in Java and different examples. this sometime also associate with super keyword which is used to denote instance of super class in Java and can be used to call overloaded constructor in Java. 6 usage of this keyword 1. to refer current class instance variable Program //Java code for using 'this' keyword to //refer current class instance variables class demo { int a; int b; // parameterized constructor demo(int a, int b) { this.a = a; this.b = b; } void display() { //displays the value of variables a and b System.out.println("a = "...
In this article we will see members of C# datatypes. Members of datatype Members of numerical datatype Experimenting with the intrinsic C# data types, understand that the numerical types of .NET support MaxValue and MinValue properties that provide information regarding the range a given type can store. In addition to the MinValue/MaxValue properties, a given numerical system type may define further useful members. For example, the System.Double type allows you to obtain the values for epsilon and infinity which might be of interest to those of you with a mathematical flare. Lets understand that by a simple program: Program using System; public class ConsoleApp { public static void Main(string[] args) { Console.WriteLine("Members of numerical datatype:"); Console.WriteLine("Max value of Int: {0}",int.MaxValue); Console.WriteLine("Min value of Int: {0}",int.MinValue); Console.WriteLine(...
Comments
Post a Comment