Deep Copy

In this chapter we are going to learn how to copy lists using the Assignment component

When we copy a list we have a Deep Copy (Copy by Value & Each copy is isolated)

Introduction

We can create this program quickly using the Quick Start component

ib_quickstart_deepcopy.png

Program Steps

After selecting the (Deep Copy) template, we will get the next steps in the Goal Designer

gd_quickstart_deepcopy.png

Creating the Program

To create this program we will use the next components

  • Assignment

  • Print Text

In the Start, The Steps Tree will be Empty

1.png

Select the (Assignment) component

2.png

We will define a list called (list)

The list will contains five items

The first three items are numbers (1,2,3)

The last two items are strings (“four”,”five”)

Left side: list

Right side: [1,2,3,”four”,”five”]

3.png

The Steps Tree will be updated

4.png

We will copy the List to another variable called (List2)

5.png

Enter the data to the Interaction Page

Left side: list2

Right side: list

6.png

The Steps Tree will be updated

7.png

Now we will set the First List to an Empty List (All items will be deleted)

8.png

Enter the data in the Interaction Page

Left side: list

Right side: []

9.png

The Steps Tree will be updated

10.png

We will print the First List (list)

11.png 12.png 13.png

We will print the Second List too (list2)

14.png 15.png 16.png

Select the (Print Text) component

17.png

Enter the data in the Interaction Page

Text: List2

Type: Expression

18.png

The Final Steps Tree

19.png