The Java do-while loop is used to iterate a part of the program several times. If the number of iteration is not fixed and you must have to execute the loop at least once, it is recommended to use do-while loop.
The Java do-while loop is executed at least once because condition is checked after loop body.
do while loop starts with the execution of the statement(s). There is no checking of any condition for the first time.
After the execution of the statements, and update of the variable value, the condition is checked for true or false value. If it is evaluated to true, next iteration of loop starts.
When the condition becomes false, the loop terminates which marks the end of its life cycle.
It is important to note that the do-while loop will execute its statements atleast once before any condition is checked, and therefore is an example of exit control loop.
Infinite do-while loop
Syntax
do{
//code to be executed
}while(true);
Program
publicclass infinite_dowhile
{
publicstaticvoid main(String args[])
{
do
{
System.out.println("Infinite while loop");
}while(true);
}
}
Output
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 do-while loop, it will be infinitive do-while loop.
You have to press ctrl+c to stop this program otherwise it will run continuously.
Environment class allows you to obtain a number of details regarding the operating system currently hosting your .NET application using various static members. To illustrate the usefulness of System.Environment, update your Main() method to call a helper method named EnvironmentDetails() . Properties Meaning ExitCode Gets or sets the exit code for the application Is64BitOperatingSystem Returns a bool to represent whether the host machine is running a 64-bit OS MachineName Gets the name of the current machine NewLine Gets the newline symbol for the current environment SystemDirectory Returns the full path to the system directory UserName Returns the name of the user that started this application Version Returns a Version object that represents the version of the .NET platform Create EnvironmentDetails() method in class under Main() method and call this method in Main() method. Program
It is true that a console user interface (CUI) may not be as enticing as a graphical user interface (GUI) or web application, restricting the early examples to console programs will allow you to keep focused on the syntax of C# and the core aspects of the .NET platform, rather than dealing with the complexities of building desktop GUIs or web sites.As its name implies, the Console class encapsulates input, output, and error-stream manipulations for console-based applications. As you can see in below table the Console class does provide some members that can spice up a simple command-line application, such as the ability to change background and foreground colors and issue beep noises in a variety of frequencies. Members of System.Console Member Meaning Beep() This method forces the console to emit a beep of a specified frequency and duration. BackgroundColor,ForegroundColor These properties
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
Comments
Post a Comment