Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

COMPUTER 10

Topic: CONDITIONAL STATEMENTS

Objectives:
At the end of the day, I will be able to:
a. state the function of If-Then-Else and Nested If statements;
b. understand Select-Case statements; and
c. properly use conditional statements when making programs.

Key Concepts:
If - serves as the beginning of the statement.
Else - serves as the connection to the next statement if the condition is found to be false.
End If – serves as the ending of the If - Then - Else structure.

Discussion:
Conditional Statements
IF-THEN-ELSE Statement
The If - Then - Else statement tests the value of a certain condition. If the condition
is true, the statement between If and Else will be executed. If the condition is false,
the statement between Else and End If will be the one executed.

Parts of the If-Then-Else Statement


If - serves as the beginning of the statement.
<condition> - is the condition that will be tested. If the condition is found to be true,
the succeeding statement/s 1 after If will be done; if the condition is false, the
statement/s 2 after Else will be done.
<Statement/s 1> - is the statement to be executed if the condition is found to be true.
Else - serves as the connection to the next statement if the condition is found to be
false.
<Statement/s 2> - is the statement to be executed if the condition is found to be
false.
End If – serves as the ending of the If - Then - Else structure.
NESTED IF STATEMENT
The Nested If statement is used when there are three or more possible outcomes.
If the condition is true, the statement between Ifand Else If will be executed. If it is false,
each Else If condition will be evaluated. When a true condition is found, the statement
immediately following each corresponding Else If will be executed. If none of the Else If
conditions are true, the statement after Else will be the one executed.

SELECT-CASE STATEMENT
The Select-Case statement is used when there are several conditions. It is easier to
understand, follow logically, and presentation than a series of Nested Ifs.
This conditional statement evaluates the text expression once and then compares it
with the expression lists. If a match is found, the statements in the corresponding
statement block are executed.
THE CONDITIONAL STATEMENTS
Conditionally executes a group of statements, depending on the value of an expression.
If condition [ then ]
[ statements ]
[ ElseIf elseifcondition [ Then ]
[ elseifstatements ]]
[ Else
[ elsestatements ]]
End If
-or-
If condition Then [statements] [ Else [ elsestatemnts ]]
Parts
condition
Required. Expression. Must evaluate to True or False, or to a data type that is implicitly
convertible to Boolean.
Then
Required in the single-line form, optional in the multiple-line form.
Statements
Optional. One or more statements following If…Then that are executed if condition
evaluates to True.
elseifcondition
Required if ElseIf is present. Expression. Must evaluate to True or False, or to data type
that is implicitly convertible to Boolean.
elsestatements
optional. One or more statements following ElseIf…Then that are executed
if elseifcondition evaluates to True.
elsestatements
Optional. One or more statements following if no previous condition or elseifcondition
expression evaluates to True.
End If
Terminates the If… Then…Else block.
Topic: LOOP STRUCTURES

Objectives:
At the end of the day, I will be able to:
d. understand how For-Next statements work;
e. state the function of Do-Loop statements;
f. use While-Wend statements to replace Do-Loop statements; and
g. identify the loop structures to be used when making programs

Fuel – Up:
Discussion:
LOOP STRUCTURES
Loop structures repeat a block of statements. These statements are executed for an
indefinite number of times while a condition is true, or until a condition becomes true.

FOR - NEXT STATEMENTS


For next statements are used to repeat statement s or a series of statements while
the value of the counter is within the start-to-end value.
The value of the counter increases by 1 automatically; however, it can be set to
increase by a specified number using the Step statement.

DO LOOP STRUCTURE
Do loop structure are statements that are executed while the condition in a Do-Loop
statement is true.

DO-UNTIL STATEMENTS
-are statements that are executed while the condition in a Do-Loop statement is
False.

WHILE-WEND STATEMENTS
-similar in structure to the Do-Loop statement.
While-Wend statement can be replace the Do While Loop in a Do-Loop statement.
One disadvantage, however, is that the While-Wend statement does not have a way
to exit prematurely. The For-Next loop has the Exit command for that purpose, while
the Do-Loop has the Exit Do.

NESTED LOOP STATEMENTS


There will be times when you need to put a loop within a loop. An example of this is
when you need to create an array or a table. When creating a loop within a loop,
always make sure that the variable of the outer loop is different from the variables of
the inner loops.

THE LOOP STRUCTURES


Repetition structures, known as loops, offer a flexible yet convenient way to
repeatedly process instructions in a program. Loops have many applications in
computer programming.
Keywords. Loops are also used in computer graphics programming, such as animation. Many
frames are displayed within a loop showing an animation. Loops are also used when programming
microprocessors and computing numerical series.There are three basic programming structures that
are used in high-level programming languages. These structures are sequential selection, and
repetition. The sequential structure is a segment of code where the statements get executed in a
sequence from top to bottom. The selection structure involves an If or a Select/Case statement,
where the program execution branches to a new line, based on the outcome of a decision. The
repetition structure, often referred to as a Loop, is used when a segment of code needs to be
executed repeatedly. Usually, a condition controls the continuation of a loop. There are different
repetition structures available in Visual Basic VB.NET.

You might also like