pawn Код:
new string1[6] = "Hello";
new string2[6] = "Hello";
for (new id; id<6; id++)
{
if(string1[id] != string2[id]) return false; //If the strings don't equal (They do though).
}
return true;
first, two arrays are being declared and
both initialized with "Hello"
or
Код:
{'H','e','l','l','o','\0'}
Both arrays have 6 elements, indexes from
0 to
5
(as we start counting from
0 in IT)
you can see clearly that it's indeed
6 elements:
Код:
{'H','e','l','l','o','\0'}
(last being the "null-char" indecating the end)
next what we're doing is a for-loop.
Out iterator variable is called
"id"
it's good practice to always set the
iterator to
0 (eg
new id=0) but it's okey like this too.
All variables created in pawn are
4 Bytes long and
contain
0 (in
Little-Endian) once created.
the condition of that for loop is:
id < 6
meaning it'll stop looping once id is
not smaller than 6.
each iteration,
id is being incremented by
1 (
id++)
now lets discuss whats inside the body of that loop.
There's a single control statement which
returns false
if it's condition
equals true.
Lets check out that condition:
string1[id] != string2[id]
that'll look like:
string1[0] != string2[0]
for the 1st iteration.
we're basically checking if one element of
string1
is the same as one of
string2.
we're using the iterator
id to select the elements.
it'll look like...
1st iteration:
string1[0] != string2[0]
2nd iteration:
string1[1] != string2[1]
and so on until our condition for that loop
no longer equals true
that being if id is not
smaller than 6.
after that loop, for some reason unknown to me, we
return true.
All this must be part of a string-checking-like function, that'd
make sense.