5 Steps to a 5 by Julie Schacht Sway

5 Steps to a 5 by Julie Schacht Sway

Author:Julie Schacht Sway
Language: eng
Format: epub
Publisher: McGraw Hill LLC
Published: 2023-09-15T00:00:00+00:00


Example—using our list of numbers:

numbers ← [1, 3, 5, 14, 15, 29]

The command:

REMOVE (numbers, 2)

Changes our list to be:

numbers ← [1, 5, 14, 15, 29]

• Length. The length of a list is the number of elements in the list.

Example—using our list of numbers:

numbers ← [1, 5, 14, 15, 29]

The command:

LENGTH (numbers)

Returns the value 5 because there are five elements currently in the list.

This number can be useful in processing items in a list. You can use references such as:

snacks[LENGTH(snacks)]

to access the last item in the list without having to know the length in advance. First, the value LENGTH(snacks) is evaluated and returns the number 5 for our current list. Our statement now looks like: snacks[5], which is the value “nuts”.

With thousands or millions of elements in a list, we can’t count them all. Even with a few dozen, people would occasionally make mistakes, and it would take so much longer than the split millisecond a computer would take. Write the code and let a computer do it!

There are many other built-in methods, and you should become comfortable with looking these up along with their format for programming languages you use in the programming language documentation.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.