Download presentation
Presentation is loading. Please wait.
1
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
2
Structure of computer languages data types (variables & constants) assignment flow control - branching - looping input/output
3
If-then-else If condition Then …. End If If condition Then …. Else …. End If If condition1 Then …. ElseIf condition2 Then …. Else …. End If
4
Relational Operators = equality > greater than < less than not equals >= greater than or equal to <= less than or equal to
5
Logical operators and (both are true) - e.g., a and b or (at least one is true) - e.g., a or b xor (exclusive or, only one is true) - e.g., a xor b not (negation) e.g., (a or b) and (not c)
6
If (asset > 5000) and (debt <= 5000) then label1.text = “I can pay off my debt” End if Dim taxexempt as Boolean Dim age as integer …. If (taxexempt) xor (age < = 18) then …. ‘code that applies to people are either taxexempt or younger than 18 …. End if Logical operators: examples
7
Select-Case Statement Dim Name as string …. Select Case Name Case “Fred” label1.text = “Hello Fred” Case “Jane” label1.text = “Hello Jane” Case Else label1.text = “Hello! Anyone Home?” End Select
8
Dim x as integer = 50 Select Case Integer.Parse(guessNumberTextBox.text) Case Is < 1 label1.text = “Way too low!” Case Is > 100 label1.text = “Way too high!” Case Is > x label1.text = “Too high!” Case Is < x label1.text = “Too low!” Case x label1.text = “You got it!” End Select If more than one case matches the test expression, only the statement block associated with the first matching case will execute. Select-Case Statement
9
Select Case Choice Case 1, 3, 7 …. Case 2, 4, 5, 6, 8 …. Case Else …. End Select Select-Case Statement
10
Select Case Choice Case 1 to 3, 7 to 10 …. Case 4 to 6 …. Case Else …. End Select Select-Case Statement
11
Loops For-Next Loops Do-Loops While-Loops
12
For - Next Loops For I = 1 to 5 …. Next I For J = 3 to 7 Step 2 …. Next J For I = 10 to 1 Step -2 …. Next I For M = 1 to N …. If x > y then Exit For End if Next M
13
Nested For-Next Loops For I = x to y …. For J = m to n …. Next J …. Next I For two dimensional data structures
14
Do-Loops Condition pre-tested Do-While loop Do-Until loop Condition post-tested Do-loop While Do-loop Until
15
Dim hungry as Boolean …. Do While hungry …. Loop Dim hungry as Boolean …. Do Until Not hungry …. Loop Dim hungry as Boolean …. Do …. Loop While hungry ‘this loop is executed as least once Dim hungry as Boolean …. Do …. Loop Until not hungry ‘this loop is executed as least once Do-Loops: pre-test vs. post-test
16
Exit-Do Do While hungry ….. if tired then exit do end if …. Loop
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.