Information Technology Reference
In-Depth Information
statement is 0. If you say that z is only two positions long since it has the value “70”, I
need to remind you that previously we had defined z as a field having 3 characters.
What will the statements
z = “70”
answer = index (x, z)
yield? What we are asking is if the string
01234567
can be found in the string
70 .
Well the 0 and the 7 can but that's about it so the result for
answer
is 0.
What will the statements
define x character (8) value “01234567”
define y character value “2”
define z character (3) value “789”
define answer integer
answer = index ( index (z, y), x)
yield? First note that
index (z, y)
will be evaluated first and the result will be 0 since none of the characters 7 , 8 or 9 can be
found in the string
y ,
which has a value of 2. Thus the line reduces to
answer = index (“0”, x )
and this is asking if 0 is in the string
x .
It certainly is so the result is that
answer
winds up with the value 1. This is a farfetched example that you probably will never
encounter but if you understand it, you have a good grasp of the
index
keyword.
For your assignment, assume your boss likes to get involved in what you're doing
- like constantly looking over your shoulder. This may seem like an outlandish request,
but just pretend you're working in the department of information technology - or
whatever it's called today - at a corporation in America. The manager asks you for this:
Write a program that will allow someone to set up some accounts for the account
number file. The user will enter last name, first name, middle initial and an account
Search WWH ::




Custom Search