Loops in Java
Loops in Java
Loops in java||A type of control structure repeats a statement a set of the statement is
known as a looping structure. It is also known as iterative or repetitive structure.in sequential
structure, all statement is executed. At once .on the other hand conditional structure executed or
skip on the base of a given condition.in some situation, it is required to repeat a statement
number of statements for a specified number of times. Looping structure is used for this
purpose .thiere different type of loop is available in c++.Java provides the powerfull construct
called a loop that controls how many times an operation or sequence of operation is performed in
succession .using a loop statement you simply tell the computer to print a string a hundred
time without having a code the print statement a hundred times as follows.
Int count =0;
While(count<100)
{
System.out.printin(“welcome to java”);
Count++;
}
The variable count its is initial value is zero.the loop check the weather (count<100)is true .it
execute loop body to print the message “welcome to java !”increment count by .it repeate and
execute the loop body until (count<100) becomes false .when count less then 100(count<100) is
false (when count reaches hundred 100) the loop terminates and the next statement after the loop
statement is executed .
This type of loop depends on a special value known as sentinel value .the loop is
terminated when the sentinel value is encountered the .these type of loops are also
known as conditional loop. For example, a loop may execute while the value of
variables is not -1 .here the -1 is sentinel value that is used to terminate the loop. The
number of iteration of the sentential_controlled loop is unknown .it depends on the
input from the user .suppose the essential value to terminate a loop is -1. if the user
enters s -1 in the first iteration, the loop will be executed only once .but if the user
enters -1 after entering many other values, the number of iterations will vary
accordingly. an initial value is commonly used with a will and do-while loops.
<a href="https://www.teeztareen.com/2019/06/nested-if-statement-in-java-
programming.html">Nested if else statement</a><br />
<a href="https://www.teeztareen.com/2019/06/what-is-jvmjava-virtual-machine.html">what is
JVM(java virtual machine)</a>