0% found this document useful (0 votes)
28 views14 pages

Loops

Loops allow blocks of code to be repeatedly executed. The main loop types are for, while, and do-while loops. For loops execute a block of code a specific number of times based on an initialization, condition, and increment/decrement. While loops repeatedly execute a block as long as a condition is true. Do-while loops are similar to while loops but execute the block once before checking the condition. Break and continue statements can alter loop execution flow - break terminates the loop entirely, while continue skips to the next iteration.

Uploaded by

Baranishankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views14 pages

Loops

Loops allow blocks of code to be repeatedly executed. The main loop types are for, while, and do-while loops. For loops execute a block of code a specific number of times based on an initialization, condition, and increment/decrement. While loops repeatedly execute a block as long as a condition is true. Do-while loops are similar to while loops but execute the block once before checking the condition. Break and continue statements can alter loop execution flow - break terminates the loop entirely, while continue skips to the next iteration.

Uploaded by

Baranishankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

LOOP

STATEMENT
Over view
• Loops statement
• Jumping statement
Loops statement

• A loop is used for executing a block of statements


repeatedly until a particular condition is satisfied.
• For example, when you are displaying number from 1 to 100
you may want set the value of a variable to 1 and display it 100
times, increasing its value by 1 on each loop iteration
Types of loop
For loop
• A for loop is a repetition control structure which allows us to
write a loop that is executed a specific number of times. The
loop enables us to perform n number of steps together in one
line.
• Syntax:
for (initialization ; condition; incre,decre)
{
// body of the loop // statements we want to execute
}
While loop

The while loop loops through a block of code as long as a


specified condition is true:
Syntax
while (condition)
{
// code block to be executed
}
Flow chart while loop
Do while loop

• Java do while loop executes the statement first and then checks
for the condition . Other than that it is similar to the while loop.

• The difference lies in the fact that if the condition is true at the
starting of the loop the statements would still be executed,
however in case of while loop it would not be executed at all.
Syntax:
do{    
//code to be executed / loop body  
//update statement   
}while (condition);    
Flow chart do while
JUMPING STATEMENT

break statement
continue statement
Break Statement
• Break Statement is a loop control statement that is used to
terminate the loop. With in the loops to break the loop
execution based on some condition.
• Inside labelled blocks to break that block execution based on
some condition.
CONTINUE STATEMENT

• This statement is used only within looping statements.

• The remaining statements in the loop are skipped. The


execution starts from the top of loop again.

• We can use continue statement to skip current iteration and


continue the next iteration inside loops.

You might also like