You are on page 1of 4

Republic of the Philippines

Laguna State Polytechnic University


Province of Laguna

LOOPS IN
JAVA

SUBMITTED BY:

JUSTINE O. DE GUZMAN
BSCPE4B

SUBMITTED TO:
MR. LOUIEVIC SANCON
I. INTRODUCTION

In programming, being concise and having a code that can be understood and can clearly

be read is an advantage, this is due to the reason that having a code like this gives an

opportunity to easily debug and know how the program works. This can also be achieved

by shortening a code. A method called loop can do this work for you. A loop can make a

code with hundreds of lines be shortened to be easily understandable. Using a loop

allows the programmer to write the code once and repeat it as many times as needed.

II. PROBLEM OF THE STATEMENT

1. How does a loop work in a Java program?

2. Advantages of using a loop in Java.

3. Is there a significant difference in each loops in Java?

III. EXAMPLE/TEST CONDUCTED

In programming languages, looping is a feature that allows the execution of a set of

instructions/functions repeatedly while some condition is true. Java provides three

methods for running loops. While all of the methods provide comparable basic

functionality, their syntax and condition checking time differ.

1. While loop in Java

While loop begins checking the Boolean condition, when true, the loop is executed.

This is also called Entry Control Loop.

2. For loop in Java


For loops provided a concise way of writing loops. Unlike while loop, a for loop

provides a shorter and way easier to debug structure by consuming the initialization,

condition and increment/decrement in one line.

3. Do while loop in Java

Similar to while loops but in this loop it checks condition after executing the

statements. It is also called Exit Control Loop.

4. Nested loops in Java

Fig1. Nested for loop Fig2. Nested while loop

Fig3. Nested do while loop Fig4. Nested while and for loop

A nested loop is a loop that is inside another loop and these are the different
combinations of a nested loop
IV. DISADVANTAGES OF LOOPS

1. Infinite loops in Java

Fig1. Infinite for loop Fig2. Infinite whjle loop

V. CONCLUSION

Therefor I can conclude that using loops in java provides a code that is shorter and

makes a code more concise. I can also conclude that there are still pitfalls in a loop and

therefore we as a programmer still needs to be more careful in using loops to ensure that

our code runs smoothly and without any errors just like in the infinite loops error that could

cause our memory to run out.

You might also like