Professional Documents
Culture Documents
VB Control Structures
VB Control Structures
|
|
|
|
This project named ³Control Structure´ is mainly
focused on the working principle of various control
Structures in VB and their implementation in
Programming.
Various Practical Examples have been included in
this project relating to real life problems for the better
understanding of the concepts.
Programming questions, Output related questions are
formed so as to improve the logical & problem
solving ability of the students.
½orking principles of various types of control
structures in VB.
Syntax & semantics of various statements in VB.
Implementation of Control structures in
Programming.
Connecting real-
real-world entities using control
structures.
Solving real-
real-life problems using control structures.
Enhancement of Logical & Problem solving ability of
the learner.
m |
Students performance will be judged/assessed by
inspecting the following factors :
Logic in Programming.
Efficiency & Effectiveness of Programs.
Usage of various control structures.
Correct syntax.
Correct code.
Following stylistic guidelines while programming i.e.
object naming conventions, meaningful object names,
proper indentation & spacing, prettyprinting style etc.
|
Students will be explained about the working
principle of individual statement with the help
of its proper syntax and example.
After explaining working principle of every
statement, students will be given Practical
Examples, implemented using VB language on
Computer.
Students will be demonstrated the usage and
working of every statement in variety of ways,
according to the options available in the
syntax.
|
Students will be given practical questions to
solve and implement using VB language.
After implementing every type of control
structure, students will be given a Home
Assignment based on the statements studied.
Students will be given a consolidated
Assignment in the end of the chapter so as to
test the logical ability of the children and their
understanding about the different types of
control structures and their implementation.
6
!
I am in teaching profession from last 12 years so this
complete lesson plan, assessment procedure,
programming questions, output related questions etc.,
are formed with my previous experience and
knowledge. Still I would like to mention few
resources I have used for the preparation of this
Project :
Text book of Informatics Practices by Sumita Arora.
Previous year CBSE Board question papers.
Computer.
|
"#
In a program, statements may be executed
sequentially, selectively or iteratively. Every
programming language provides constructs to
support sequence, selection or iteration. So
there are three types of programming
constructs :
Sequential Constructs
Selection Constructs
Iterative Constructs
$
The sequential construct means the statements
are being executed sequentially. This
represents the default flow of statements.
Stament 1
Stament 2
Stament 3
The selection construct means the execution of
statement(s) depending upon the condition-
condition-
test. If a condition evaluates to true, a course-
course-
of-
of-action (a set of statements) is followed
otherwise another course-
course-of-
of-action is followed.
This construct is also called decision construct
as it helps in decision making.
%&%
Condition
? Statement 1 Statement 2
&
Statement 1 m
%
&%
Statement 2
The iterative or repetitive constructs
means repetition of a set-
set-of-
of-statements
depending upon a condition-
condition-test. A set-
set-
of-
of-statements are repeated again and
again till the condition or Boolean
Expression evaluates to true. The
iteration constructs are also called as
looping constructs.
&
Condition
?
'
Statement 2
VB provides two types of selection construct :
è 1) If statement
è 2) Select Case statement
The If Statement : If statement of VB comes in
various forms & are given below:
1) If..Then Statement
2) If..Then..Else Statement
3) If..Then..ElseIf Statement
4) Nested Ifs
&
ef. : An If..Then statement tests a particular
condition; if the condition evaluates to true, a
course--of-
course of-action is followed otherwise it is
ignored.
Syntax :
Example 2 :
If txtAge.Text>=18 Then
Print ³You are eligible to vote´
End if
&(
If..Then..Else statement provides an alternate choice
to the user i.e. if the condition is true then a set of
statements are executed otherwise another set of
statements are executed.
Syntax :
Example 2 :
If Num Mod 2=0 Then
Print ³It is an Even Number´
Else
Print ³It is an Odd Number´
End If
&(&
If..Then..ElseIf statement is used to test a number of mutually
exclusive cases and only executes one set of statements for the
case that is true first.
Syntax :
Syntax :
For <counter Variable>=<start_val> To <end_val> Step
<increment/ecrement Value>
µ One or more VB Statements
Next <counter Variable>
('
è Example 1 : Generate natural no¶s from 1 to
100
For I = 1 To 100
Print I
Next I
è Example 2 : Generate first 20 even no¶s.
For E = 2 to 40 Step 2
Print E
Next E
Î ('
Example 3 : Generate odd no¶s from 100 to 30
in a list box.
For O = 99 to 31 Step -2
ListO.AddItem(O)
Next O
Example 4 : Generate table of any number N.
For T = 1 To N
Print N; ³*´; T; ³=´; N*T
Next T
Î ('
Example 5 : Find factorial of a given number
N.
:
Fact=1
For I= 1 to N
Fact = Fact * I
Next I
Print ³Factorial of ´; N; ³=´; Fact
:
0 m +
½rite Programs for the following problems :
1) To Generate all the natural no¶s from 200 to
500.
2) To Generate the table of 10.
3) To Generate all the even no¶s from 200 to
400 in reverse order.
4) To Print first 20 multiples of the number
input by the user.
o ½hile..Loop : o ½hile loop is an entry
controlled loop in which the condition is
placed at the entry point. This statement
executes the statements specified in the body
of the loop till the condition evaluates to true.
The loop may not be executed at all the if the
condition is initially false.
Syntax :
o
One or more VB Statements
Loop ½hile <condition or Boolean Expression>
('
Example 1 :
o
num = InputBox (³Enter a number´)
sum = sum + num
Loop ½hile num < > 0
Here the statements inside the loop will be
executed once no matter what the comparison
test evaluates to.
!
o Until loop is an entry controlled loop in which the
condition is placed at the entry point. This statement
executes the statements specified in the body of the
loop till the condition evaluates to false. The loop
may not be executed at all the if the condition is
initially true.
Syntax :
o
One or more VB Statements
Loop Until <condition or Boolean Expression>
('
Example 1 :
o
num = InputBox (³Enter a number´)
sum = sum + num
Loop Until num = 0
Here the statements inside the loop will be
executed once no matter what the comparison
test evaluates to.
//
½hile..½end loop is functionally equivalent to
the o ½hile..Loop. It executes a set of VB
statements till the condition evaluates to true.
Syntax :
½hile <Condition>
one or more vb statements
½end
('
Example 1 : Generate the sum of first 10
natural no¶s
I=1
½hile I<=10
Sum = Sum + I
I=I+1
½end
Print ³Sum of 10 natural no¶s = ´ ; Sum
-
A loop within another loop is called as Nested
Loop.
Example :
For I = 1 to 5
For J = 1 To 3
Print J
Next J
Print
Next I
/ 0 & -
In nested loops the inner loop is executed
completely for one time execution of the outer
loop. In the Previous example the Inner Loop
will be executed three times for every
execution of the outer loop.
Nested loops are very useful when there is a
requirement to generate different kind of
patterns as output.
('
(' |
#
*
+ +
, , ,
1 1 1 1
2 2 2 2 2
Sol :
For I = 1 To 5
For J = 1 To I
Print I;
Next J
Print
Next I
0 m , 3 -
0 m , 3
½rite programs to generate the following patterns :
1) 1 2) 1 2 3 4 5
12 1234
123 123
1234 12
12345 1
3) A
AB
ABC
ABC
0 m 1 3
0 m 1 3
6 4
Specify the output of the following output related
questions, assume that variables are declared :
G sum=0 sum = 0
For I = 1 To 4 p=2 : q=4
For J = 1 To 3 o ½hile p<=10
sum = sum + J If p Mod 2 = 0 Then
Next J sum = sum + p
Print ³Sum = ´;sum End If
Next I p=p+1
Loop
Print sum
$
R=5 : S=3 M=2 : N=4
o o Until M>12
Print R, S N=N+M
R=R+1 If M Mod 3 = 0 Then
If R = 7 Then N=N-M
Exit o Else
End If N=N+M
S=S+R End If
Loop ½hile R <=10 M=M+1
Loop
Print M, N
0 m %% 2
0 m
Programming Questions : evelop programs for the
followings :
To generate the mirror image of the number entered
by the user.
To generate the prime numbers between 100 and 700.
To Check whether the number entered by the user is a
prime number or not.
To print first 30 multiples of the number entered by
the user.
To generate the factorial of the number input by the
user.
0 m %% 2
0 m
To generate the Fibonacci series upto first 15 terms
i.e. 0 1 1 2 3 5 8««««..
To find the sum of all the numbers divisible by 7
from 100 to 200.
To check whether the year entered by the user is leap
year or not.
To find and print the sum of digits of the number
entered by the user.
To find and print the product of digits of the number
accepted from the user.
m
Students will be given Programming problems,
output and error finding questions to test
whether they understood the various concepts
taught through this presentation.
Various parameters are used to check the
understanding of the concept and its
implementation in Programming.
All the parameters mention in the next slide
have their own importance, so all these
parameters needs to be checked by the Teacher
teaching Programming.
m
| & # 6 0
Logic Correct/Incorrect
Effective Yes/No
Efficient Yes/No
Coding Correct/Incorrect
Syntax Correct/Incorrect
Following Yes/No
Naming
Conventions