Working with Loop Statements

Practice Labs Module
Time
18 minutes
Difficulty
Intermediate

Welcome to the "Working with Loop Statements" Practice Lab. In this module, you will be provided with the instructions and devices needed to develop your hands-on skills.

Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Overview

Introduction

Welcome to the Working with Loop Statements Practice Lab. In this module, you will be provided with the instructions and devices needed to develop your hands-on skills.

Exam Objectives

The following exam objective is covered in this lab:

  • 3.3 Complete and debug loops

Lab Duration

It will take approximately 20 minutes to complete this lab.

Exercise 1 - Working with Loops

In computer programming, you can write code to execute a set of instructions, operations, or statements for several times until a specific condition is met. This process is known as iteration. You can implement the iteration process in scripts with the help of loops. A loop repeatedly runs through the set of instructions and stops execution on fulfilling the condition specified. The following types of loops are available in JavaScript:

  • for loop - You can use this loop if you want to repeat the execution of a code block multiple times.
  • for/in loop - This loop is a type of for loop. It iterates through the properties of a declared object.
  • while loop - This loop executes the set of statements while the specified condition returns a true value. The moment the specified condition returns a false value, the while loop will not perform the iteration. Thus, the while loop checks the condition and then performs the iteration.
  • do/while loop - This loop is a type of while loop. It first executes the code block and then checks if the condition is true. The do/while loop then repeats the execution until the condition returns a true value.

In this exercise, you will learn to use all these types of loops in the To Do List page. You will perform the following tasks:

  • Task 1 - You will download the Visual Studio Code workspace (ToDoList) from the Intranet and open the HTML page named ToDoList.html in the ToDoList workspace.
  • Task 2 - You will write JavaScript code to use for and for/in loops in the To Do List page.
  • Task 3 - You will write JavaScript code to use while loop in the To Do List page.
  • Task 4 - You will write JavaScript code to use a do/while loop in the To Do List page.

Learning Outcomes

After completing this exercise, you will be able to:

  • Use loops in JavaScript
Learning Partner
Comprehensive Learning

See the full benefits of our immersive learning experience with interactive courses and guided career paths.