Unit IV (Selection / If statements /conditional execution)

CS 1130 Visual Basic—Fall 2016

Day 11 — Unit III (Booleans) review & Comp. Demo.

Logistics

Unit III Questions

If you have any questions about the Unit III Practice items or the sample Comp.Demo. I distributed, now is the time to ask.

Unit IV Introduction (see day 12 notes)

We will begin consideration of the programming fundamental of selection. But we will halt at 4:10 pm to allow time for the competency demo for Unit III.

Next Time

Day 12 — Unit IV Intro

Logistics

Review Unit III Competency Demo

Selection

At the start of the course, I mentioned the basics of computing—data & actions and the basics ways of organizing actions—sequence, selection, repetition, and modularization. Programming is figuring out what actions are needed and then organizing them in a way that accomplishes our overall task.

So, what does today's topic, "selection" look like. You are familiar already with the idea of if something is true, do something. That is selection. In programming we have an If statement; actually we have several variations of the If statement. The two basic forms are:

	' actions required before the IF

	If  true  Then
	    ' set of actions
	End If
	
	' actions required after the IF

and

	' actions required before the IF

	If  true  Then
	    ' set of actions
	Else
	    ' alternate set of actions
	End If
	
	' actions to occur after the IF

Questions? ... Let's explore the various parts and see what we can deduce about the If statement.

That is how the if statement works. Questions? Comments? Wonderings?

There is one particular way of using if statements that you should be aware of—as a flag. Sometimes there are multiple occasions to test a condition and any or all of the tests could determine the action to be taken when all tests are completed. The pattern here is something like the following.

	Dim okay As Boolean = True

	...
	
	If  <bad test 1>  Then
	    okay = False
	End If
	
	If  <bad test 2>  Then
	    okay = False
	End If
	
	.
	.
	.
	
	If okay Then
		' do okay action
	else
		' do NOT okay action
	End IF

Examples

Next, we will look at slightly more complex examples and alternatives for doing them. Let's look at an example involving a student asking about their grade (its a silly example, but one we are familiar with). Even a simple problem like get a score from the user and determine the grade involves some thinking in order to code it correctly. Some considerations are:

So a simple IF statement could check to see if the user entered a number for a score. Typically we want to do something with the score once we know the input is okay. That would go in the ELSE part of the IF we did above.

Here is some example code—what was done in class may differ.

Next Time

Day 13 — Work & Questioning RE Unit IV Practice

Logistics

Project Meeting

Remember, you need to be deciding on a project. Review the project assignment description noting the project checklist information. Think about "apps" that might be useful in your field. If you can't think of anything, talk with your friends or come see me. We have the next three weeks or so to do meetings about your project, and, I will be gone March 8 - 12.

Questions? Comments? Wonderings?

Unit IV Questions

Next Time

Day 14 — Unit IV Comp. Demo.

Logistics

Unit IV Questions

If students are ready, complete the Unit IV competency demo.

Next Time

Day 15 — Unit IV Comp. Demo.

Logistics

Remember that the project proposal meeting needs to occur soon. Listed due date is this Friday but I'll change that to next Tuesday. Questions about the project?

Unit IV Competency Demo

If students are ready, complete the Unit IV competency demo.

Next Time