Chapter 5 Introduction to Control Structures For Visual

  • Slides: 14
Download presentation
Chapter 5 Introduction to Control Structures For Visual Basic. NET 淡江大學資管系 – 商用程式設計

Chapter 5 Introduction to Control Structures For Visual Basic. NET 淡江大學資管系 – 商用程式設計

Introduction to Control Structures Control structures allow you to control the flow of your

Introduction to Control Structures Control structures allow you to control the flow of your program's execution. If left unchecked by control-flow statements, a program's logic will flow through statements from left to right, and top to bottom. While some very simple programs can be written with only this unidirectional flow, and while some flow can be controlled by using operators to regulate precedence of operations, most of the power and utility of any programming language comes from its ability to change statement order with structures and loops. 淡江大學資管系 – 商用程式設計

Introduction to Control Structures • • Decision Structures An introduction to decision structures used

Introduction to Control Structures • • Decision Structures An introduction to decision structures used for branching. Loop Structures An introduction to loop structures used to repeat processes. 淡江大學資管系 – 商用程式設計

Introduction to Control Structures n Decision Structure • If. . . Then. . .

Introduction to Control Structures n Decision Structure • If. . . Then. . . Else • Select Case 淡江大學資管系 – 商用程式設計

Introduction to Control Structures n IF … THEN 可與邏輯運算子配合 Note: OR運算時的 Short-Curuited If condition

Introduction to Control Structures n IF … THEN 可與邏輯運算子配合 Note: OR運算時的 Short-Curuited If condition Then statements End If 淡江大學資管系 – 商用程式設計 T F

Introduction to Control Structures n If. . . Then. . . Else If condition

Introduction to Control Structures n If. . . Then. . . Else If condition 1 Then [statementblock-1] Else [statementblock-2] End If 淡江大學資管系 – 商用程式設計 F T

Introduction to Control Structures n If. . . Then. . . Else If condition

Introduction to Control Structures n If. . . Then. . . Else If condition 1 Then If condition 2 Then [statementblock-1] Else [statementblock-2] End If Else [statementblock-3] End If 淡江大學資管系 – 商用程式設計 If condition 1 Then [statementblock-1] Else. If condition 2 Then [statementblock-2]. . . Else [statementblock-n] End If

Introduction to Control Structures n Select Case testexpression [Case expressionlist 1 [statementblock-1]] [Case expressionlist

Introduction to Control Structures n Select Case testexpression [Case expressionlist 1 [statementblock-1]] [Case expressionlist 2 [statementblock-2]] … [Case Else [statementblock-n]] End Select 淡江大學資管系 – 商用程式設計 T F T F

Introduction to Control Structures n Select Case – Example Select Case Access. Code Case

Introduction to Control Structures n Select Case – Example Select Case Access. Code Case Is < 1000 … Case 1645 To 1689 … Case 8345 … Case 999898, 100006, 200000 … Case 3000, 4000 To 4500 … Case Else … End Select 淡江大學資管系 – 商用程式設計

Introduction to Control Structures n Loop Structures • Do…Loop • While…End While • For.

Introduction to Control Structures n Loop Structures • Do…Loop • While…End While • For. . . Next 淡江大學資管系 – 商用程式設計

Introduction to Control Structures n Do. . . Loop Do While condition statements Loop

Introduction to Control Structures n Do. . . Loop Do While condition statements Loop Do Until condition statements Loop Do statements Loop While condition Do statements Loop Until condition 淡江大學資管系 – 商用程式設計

Introduction to Control Structures n For. . . Next For counter = start To

Introduction to Control Structures n For. . . Next For counter = start To end [Step increment] statements Next [counter] Note: The arguments counter, start, end, and increment are all numeric. 淡江大學資管系 – 商用程式設計

Introduction to Control Structures n Exit Do; Exit For Do statements Exit Do statements

Introduction to Control Structures n Exit Do; Exit For Do statements Exit Do statements Loop While condition statements 淡江大學資管系 – 商用程式設計 強迫脫離