Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C For Dummies 2nd Ed 2004.pdf
Скачиваний:
43
Добавлен:
17.08.2013
Размер:
8.34 Mб
Скачать

Chapter 16: C the Loop, C the Loop++ 213

Technically, these doojabbies are referred to as assignment operators. Don’t memorize that term. Even I had to look it up.

Hey: It’s a good idea to stick a sticky note on Table 16-2 or flag it by dog­ earing the page. These cryptic shortcuts aren’t easy to remember.

One way to remember that the operator (+, , *, or /) comes first is to look at the wrong way for subtraction:

var=-5

This is not a shortcut for var=var-5. Instead, it sets the value of variable var equal to negative-five. Ipso fasto, var-=5 must be the proper way to do it.

Remember that these mathematical-shortcut cryptic operators aren’t nec­ essarily limited to use in for loops. Each of them can be a C language statement unto itself, a mathematical operation to somehow pervert a variable’s value. To wit:

term+=4;

This statement increases the value of the variable term by 4.

The answers

In CHANT.C, modify Line 7 to read:

for(i=2;i<10;i+=2)

In 1000.C, modify Line 7 to read:

for(i=2;i<10;i+=5)

In both cases, you change the longer equation i=i+x to its shorter variation, i+=x.

214 Part III: Giving Your Programs the Ability to Run Amok