Previous Page
Next Page

Chapter 5 Quick Reference

To

Do this

Add an amount to a variable

Use the compound addition operator. For example:

variable += amount;

Subtract an amount from a variable

Use the compound subtraction operator. For example:

variable -= amount;

Run one or more statements while a condition is true

Use a while statement. For example:

int i = 0; 
while (i != 10) 
{ 
    Console.WriteLine(i); 
    i++; 
}

Alternatively, use a for statement. For example:

for (int i = 0; i != 10; i++) 
{ 
    Console.WriteLine(i); 
} 

Repeatedly execute statements one or more times

Use a do statement. For example:

int i = 0; 
do 
{ 
    Console.WriteLine(i); 
    i++; 
} 
while (i != 10);

Previous Page
Next Page