Chapter5 - Chapter 5 Controls Structures: Loops 1...

Info iconThis preview shows pages 1–34. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Chapter 5 Controls Structures: Loops
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Introduction Previously we have learned how to write simple programs that used if statements and simple visual tools. In this chapter we will learn about loops . Loops are necessary to execute sections of code repeatedly.
Background image of page 2
3 Overview Loops More graphical tools Sample Programs SumToN.vb SmallestInt.vb BubbleSort.vb
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Loops Counting Loops For…Next Conditional Loops Do While Loop, Do Until Loop Do Loop While, Do Loop Until Nested Loops (loop within a loop) SumToN.vb SmallestInt.vb BubbleSort.vb
Background image of page 4
5 Counting Loops Counting loops repeat a given number of times. For-Next statement is an example of a counting loop. Index variable Value that i has to reach for the loop to stop Code At this point i is incremented by one automatically and the process begins again Initializes i to 1
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 SumToN.vb New Concepts GroupBox CheckBox For-Next Loop
Background image of page 6
7 SumToN.vb This program will compute the sum of consecutive integers from 1 to n (integer).
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 SumToN.vb If selected, the program will also output the sum of all the odd integers between 1 and n . CheckBox GroupBox
Background image of page 8
9 GroupBox Control Designing a nicer layout Sectioning off a set of visual controls from another Click on Group Box GroupBox
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 CheckBox Control The CheckBox is used for binary (yes/no) inputs, typically to enable the user to check on/off an option. In SumToN.vb the check box is used to deterimine whether to display the odd sum. Click on CheckBox
Background image of page 10
11 Label Properties The BorderStyle will be changed to give a label the more appealing look. The BackColor will also be changed. BackColor Select LightGray BorderStyle Select Fixed3D
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
12 For-Next Loop
Background image of page 12
13 For-Next Loop i=1 i <= n Set i = i+2 FALSE TRUE Execute statements in loop Exit loop Regular program flow Logic Diagram
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
14 Debugging Debugging means fixing bugs (errors). We will use the built-in debugger of Visual Studio to identify and correct run-time errors. This is essential when developing complex programs. The debugger can also help us understand how a program runs. The next few slides will show in detail how a for-next loop works.
Background image of page 14
15 Right click on this line
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
16 Breakpoint
Background image of page 16
17 Select Debug Breakpoint
Background image of page 17

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
18 Select Start Debugging
Background image of page 18
19 Make sure the Autos window is showing Autos Notice you can also press Ctrl+Alt+V,A
Background image of page 19

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
20 Type 3 for n Click Evaluate
Background image of page 20