Game Development Reference
In-Depth Information
You'll find a file called ]nn]uOa]n_d*bh] in the =nn]uOa]n_d folder of the chapter's source files. Open
it as a project and take a look at its I]ej[=nn]uOa]n_d*]o file. It uses an eb statement inside a bkn
loop to check whether the array contains an element called ikomqepk. Once the eb statement finds
the correct element, a ^na]g directive runs to stop the loop from continuing:
l]_g]ca
w
eilknpbh]od*`eolh]u*Ikrea?hel7
lq^he__h]ooI]ej[=nn]uOa]n_datpaj`oIkrea?hel
w
++`a_h]na]nn]u
lner]par]n[_khha_pekjF]n6=nn]u7
lq^he_bqj_pekjI]ej[=nn]uOa]n_d$%
w
++Ejop]jpe]pa]nn]u
[_khha_pekjF]n9jas=nn]u$%7
++=``ahaiajpopk]nn]u
[_khha_pekjF]n*lqod$bhu%7
[_khha_pekjF]n*lqod$ikomqepk%7
[_khha_pekjF]n*lqod$^aa%7
++Oa]n_d]nn]u
bkn$r]ne6ejp9,7e8[_khha_pekjF]n*hajcpd7e''%
w
eb$[_khha_pekjF]nWeY99ikomqepk%
w
pn]_a$Ikomqepkbkqj`]plkoepekj'e%7
^na]g7
y
y
y
y
y
If you test it, you'll see this output:
Ikomqepkbkqj`]plkoepekj-
Because you include a ^na]g directive, the loop stops at that point. It never checks element W.Y, which
is a good thing. The loop has found what it's looking for, so it doesn't need to check. Using bkn loops
to search arrays is a basic programming technique that you'll be using frequently from now on.
You'll need a bit of practice with arrays before you start to feel comfortable using them in your own
code. Spend a bit of time with these example files, make some changes, and follow the way your
changes affect the output.
 
Search Nedrilad ::




Custom Search