Lecture-21(Structured Programming)

Lecture-21(Structured Programming) - statement with...

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

View Full Document Right Arrow Icon
Structured Programming: Decisions
Background image of page 1

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

View Full DocumentRight Arrow Icon
Structured vs. Unstructured Programming Unstructured programming characterized by uncontrolled use of GoTo statements e.g. Sub Average() 1: g=InputBox(“Enter value:”) If g < 0 Then GoTo 2 s = s+g i = i+1 GoTo 1 2: If i=0 Then GoTo 3 a=s/i GoTo 4 3: a=0 4: MsgBox a EndSub A really convoluted way to calculate the average of positive numbers Syntax for the line identifier
Background image of page 2
Structured Programming Loops and If statements serve to give structure to the program Sub Average() Do g = InputBox(“Enter Value:”) If g<0 Then Exit Do s = s + g i = i + 1 Loop If i > 0 Then a = s / i Else a = 0 Endif MsgBox a EndSub No re-direction using GoTo statements
Background image of page 3

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

View Full DocumentRight Arrow Icon
If/Then/Else Decision Structure Syntax Condition is a logical expression with a True or False outcome [TrueStatements] are a set of statements that are evaluated if the Condition is True If Condition Then [truestatements] Else [falsestatements] Endif Good Idea to enter If
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: statement with indentation i.e. the True and False statements are indented Single Decision Structure A reduced form of the If/Then/Else statements where the False Alternative does not exist Single line If statement If Condition Then [truestatements] Endif If Condition Then [truestatement] Only one statement allowed If Condition Then [truestatement] Else [Falsestatement] If/Then/Elseif Structure Quite often the false option of an Ef/Then/Else might involve another decision There are more than two options to a problem If Condition1 Then [truestatements1] Elseif Condition2 Then [truestatements2] Elseif Condition3 Then [truestatements3] Else [falsestatements] Endif If Condition1 Then [truestatements1] Elseif Condition2 Then [truestatements2] Elseif Condition3 Then [truestatements3] Endif A variation without the Else...
View Full Document

This note was uploaded on 04/27/2008 for the course PGE 310f taught by Professor Srinivasan during the Spring '08 term at University of Texas at Austin.

Page1 / 6

Lecture-21(Structured Programming) - statement with...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online