java programming constructs 3 mis 3023 business programming concepts ii the university of tulsa...

Post on 13-Jan-2016

215 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Java Programming Constructs 3

MIS 3023

Business Programming Concepts II

The University of Tulsa

Professor: Akhilesh Bajaj

All slides in this presentation ©Akhilesh Bajaj, 2006. All rights reserved

Objectives

• Continue to understand programming constructs in Java:-the while loop-the do-while loop-the for loop

Look at the break statementLook at the continue statement

Let’s get started!

Nesting for Loops

To get the above output, we can use:

Nesting for Loops

A program that will list all the letters contained in a string and will also count the number of different letters.

The break Statement Syntax:break;

• Breaks out of a loop or switch statement• If used in an if statement, then the if statement HAS to be in a loop or a switch, and the program will break out of that container loop or switch statement.

Can we write the above with a for loop?

The break Statement

We can also create a labeled break, to break out of nested loops.

label_name:loop1 loop 2

loop3break label_name;

end loop3end loop2

end loop1

Will break out of all the loops and proceed with the next statement below the 3 labeled loops.See example of ListLetters.java

The continue Statement Syntax:continue;

• Continues with the next iteration of the loop.

• See program ContinueDemo.java

• The continue statement can also refer to a label, if we want to continue the next iteration of an outer loop.

Fun In Class Example

Write a program called

MultiplicationTable.java

that prints the multiplication table for a particular integer, input by the user, times 1 till times 12 of that integer.

top related