O'Reilly logo

Programming with Java by Sunil Patekar, Mahesh Bhave

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 5

LOOPS

The real strength of computers and computer programs is in looping. A computer can execute thousands of instructions in no time. If we have to code each and every instruction, we will need days to write a single program. The few instructions we write are repeated hundreds of time faithfully by the computer. For this purpose, we need loops.

In Java, just like C or C++, there are three structures for looping around a given code. They are

  • for loop
  • while loop
  • do-while loop

Statements break and continue are used mainly in these structures. Therefore, we will be discussing these statements too. Let us start with the for loop statement.

5.1 for Loop

for loop is the most useful statement (facility) in any programming language. A typical ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required