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;
System.out.printin(“welcome to java”);
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 .
Loop is used basically for two purposes.
1. To execute a statement or number of statements for a specified number of times. For example, a user may display your name 10 time .
2. To use a sequence of values . for example, a user may display a set of natural numbers from 1 to ten.
There are three types of loop available in c++ .these are follow .
1.While loop 2.do while loop 3.for loop
- Counter_ controlled loops
This loop depends on the value of a variable known as the counter variable.
The value of counter variables is incremented or decremented each time the body of the loop is executed .this loop is terminated when the value of the counter variable reaches a particular value. The number of iterations of a counter controlled loop is known in advance .the iteration of the loop depends on the following.
1.initial value of the counter variable.
3.Increment or decrement value
- Sentinel controlled loops
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.
Educational determination website
Nested if else statement
If else statement in java
If statement in java
A simple program in java for begnners
System.out.printin() in java
Public static void main ( String args ) in java program.
The basic structure of the java program.
Data types in java with examples(write and video tutorial
what is JVM(java virtual machine) java 8 features
What is Java programming and java history