Loop In Java

Loop:- It is a control structure used to perform the task in represents manners. That is used to perform the same task multiple numbers of times.

The loop has three parts.

1) Initialization:- It specified starting of the loop.
2) Condition:- It specified the range up to which the loop will be executed.
3) Increment / Decrement:- It specified the statement through with the initialized value is both Increment and Decrement to retch the condition.

Types of a loop:- According to the working technique, there are two types of loop.

1)Entry controlled loop
2)Exit controlled loop

1) ENTRY CONTROLLED LOOP:- It is the form of a loop in which the condition is checked the first body of the loop is executed.
There are two ways of an entry controlled loop.

  1. While loop
  2. For loop and

While loop:- While is an entry controlled loop in which the condition is checked first then the body of my loop is executed.

while loop

 

 

 

 

 

 

while loop example

 

 

 

 

 

 

 

 

 

 

 

For loop:- For is an entry controlled loop in which all the part of the loop are written and at one place separated by a semicolon (;).

for loop syantax

for loop example

EXIT CONTROLLED LOOP:- It is the form of a loop in which the body of the loop is executed first then the condition is true. If the condition is true loop will be repeated otherwise not.

There is one type of Exit controlled loop.

Do While:- Do While is an exit controlled loop in which the body of the loop is executed first then the condition is true when the loop is repeated otherwise not.

do while syantax

do while example

Ques:  Different between while and do while loop.
Ans:– The main difference between while and do while. The do while will be executed at least on even the condition is false.

Nested loop:- Loop wrote inside another loop is called as a nested loop. There will be at least two loops the first loop is called outer and second loop is called as inner. For every step outer loop, the inner will start and execute till its termination. The outer loop satisfied the number of lines and the inner loop is satisfied the number of data in each line.

nested loop

Labelled loop:- Loop having a name is called as a labelled loop. Labelled is the name given to the loop.

labelled loop

 

 

 

Labelled break:- When a break is used with the label name then it is called as a labelled break.

Labelled break

 

 

 

 

Labelled continue:- When label name is used with continuous it is called as labels continue.

Labelled continue

 

 

 

 

 

 

 

 

Switch case:- Switch case is the control structure used to select an operation from the multiple. It is a replacement of if_else_if. It is used to developed menu based program.

switch case

 

 

 

 

 

 

 

 

• Variable specified the variable having value.
• Case specified the possible value of the variable. When all the case fails default will be executed.
EXAMPLE: –

Ques.-Input the day number display the name of the day.

Input the day number display the name of the day

 

Leave a Reply