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

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

1 Chapter 5 Controls Structures: Loops

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

View Full Document
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.
3 Overview Loops More graphical tools Sample Programs SumToN.vb SmallestInt.vb BubbleSort.vb

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

View Full Document
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
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

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

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

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

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

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

View Full Document
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
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

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

View Full Document
12 For-Next Loop
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

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

View Full Document
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.
15 Right click on this line

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

View Full Document
16 Breakpoint
17 Select Debug Breakpoint

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

View Full Document
18 Select Start Debugging
19 Make sure the Autos window is showing Autos Notice you can also press Ctrl+Alt+V,A

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

View Full Document
20 Type 3 for n Click Evaluate