Objectives

Students will be able to:

  • develop flowcharts to represent a variety of loop structures.

Algorithm

An algorithm is a defined set of steps that can be followed to solve a problem.

Logging In

Loop Comparisons

A login system gives a user 3 chances to log in successfully.

Let's look at different loop options to allow this to happen in Java.

This unit offers food-for-thought and an opportunity to review key concepts so far.

Copy the starter code into a new project in your IDE.

Task 1

Open the worksheet and complete the tasks.

Helper Video

If you need help to understand the code, check out the helper video.

KEY POINTS

We can use any loop structure to solve a given problem.

Commonly however:

  • For loops are used when we know how many iterations will be required.
  • While loops are used when we don’t know how many iterations will be required.
  • Do While loops are used when we don’t know how many iterations will be required, but there will be at least one!

Tags

whilepre-condition loop do whileANSI for .equals() count-controlled loop ! post-condition loop&& ||Logical operators