Chapter 4: Flow Control


Overview

All of the C# code you've seen so far has had one thing in common. In each case, program execution has proceeded from one line to the next in top-to-bottom order, missing nothing. If all applications worked like this then you would be very limited in what you could do.

In this chapter, you look at two methods of controlling program flow, that is, the order of execution of lines of C# code. These two methods are:

  • Branching, where you execute code conditionally, depending on the outcome of an evaluation, such as "only execute this code if myVal is less than 10."

  • Looping, or repeatedly executing the same statements (for a certain number of times or until a test condition has been reached).

Both of these techniques involve the use of Boolean logic. In the last chapter you saw the bool type, but didn't actually do much with it. In this chapter you use it a lot, and so the chapter will start by discussing what is meant by Boolean logic so that you can use it in flow control scenarios.




Beginning Visual C# 2005
Beginning Visual C#supAND#174;/sup 2005
ISBN: B000N7ETVG
EAN: N/A
Year: 2005
Pages: 278

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net