Programming Lecture #4 CS 101 Autumn 2006 Tariq Jadoon
In Lecture #3 Swapping Variables Conditional Code
Swapping the Contents of Two Variables X = 10 Y = 20 Temp = Y Y = X X Y Temp 20 10
Swapping the Contents of Two Variables X = 10 Y = 20 Temp = Y Y = X X = Temp X Y 10 Temp 20
Debugging Using the Immediate Window as a scratchpad Placing Breakpoints Single stepping (F8) Placing Watches
Conditional Code VB has a number of block structures for conditional code: IF condition THEN action IF condition THEN action1 action2... END IF
Conditional Code (contd.) IF condition THEN action1 … ELSE action2 … END IF
Today Conditional Code (contd.) Loops
Conditional Code (contd.) IF condition1 THEN action1 … ElseIf condition2 THEN action2 … ElseIf condition3 THEN action3 … Else default action … END IF
Loops Repeat code –Counter Initial value Terminal Value Increment (step size)
Loops For c = 1 to 10 Step 2 action1 action2 … Next c Initial Value Terminal Value Increment Value Body of the loop Increment and check terminating condition