Class 7 Exam  >  Class 7 Notes  >  Computer Science for Class 7  >  Textbook: Basic Programming- Control and Repetition

Textbook: Basic Programming- Control and Repetition | Computer Science for Class 7 PDF Download

Download, print and study this document offline
Please wait while the PDF view is loading
 Page 1


Jyoti [after seeing the interesting graphics]: Using a repetitive mathematical sequence, we can easily 
draw interesting patterns.
Moz: Yes. Execute the program below, step by step, and understand how a sequence starts, is 
repeated and ends. This program uses the for statement.
Tejas: First the graphics output screen and the text output screen are cleared.
Jyoti: The variable i is assigned the value 1 at the start of the repetition. [Memory i = 1]
Tejas: The sequence to be repeated starts. Square of i is calculated and assigned to isquare. Then 
isquare is printed in text output area.  [Memory isquare = 1]
Jyoti: isquare is used for x and y coordinates in the rectangle statement. The length and breadth of 
the rectangle is set to i. A rectangle is output in the graphics output area. Rect 1,1,1,1
i
i
i
i
i
i
i
i
i
i
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
so on until i>10
1
2
3
4
5
6
7
8
9
10
1
4
9
16
25
36
49
64
81
100
Memory
Aim: In this lesson, you will learn:
- Control the execution of a program.
- Repeat and decision making statements.
- Managing lists with arrays.
BASIC Programming: 
Control and Repetition 
10
       if SP > CP
Profit=111
1 1 1 1 1
CP P C
1 1 1
1 1 1 1 1 1 1 1 1 1
Memory 
clg
for i = 1 to 20
isquare=i*i
Print isquare
color blue
rect isquare,isquare,i,i
next i
T ext output
Graphics output
PROGRAM
OUTPUT
Page 2


Jyoti [after seeing the interesting graphics]: Using a repetitive mathematical sequence, we can easily 
draw interesting patterns.
Moz: Yes. Execute the program below, step by step, and understand how a sequence starts, is 
repeated and ends. This program uses the for statement.
Tejas: First the graphics output screen and the text output screen are cleared.
Jyoti: The variable i is assigned the value 1 at the start of the repetition. [Memory i = 1]
Tejas: The sequence to be repeated starts. Square of i is calculated and assigned to isquare. Then 
isquare is printed in text output area.  [Memory isquare = 1]
Jyoti: isquare is used for x and y coordinates in the rectangle statement. The length and breadth of 
the rectangle is set to i. A rectangle is output in the graphics output area. Rect 1,1,1,1
i
i
i
i
i
i
i
i
i
i
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
so on until i>10
1
2
3
4
5
6
7
8
9
10
1
4
9
16
25
36
49
64
81
100
Memory
Aim: In this lesson, you will learn:
- Control the execution of a program.
- Repeat and decision making statements.
- Managing lists with arrays.
BASIC Programming: 
Control and Repetition 
10
       if SP > CP
Profit=111
1 1 1 1 1
CP P C
1 1 1
1 1 1 1 1 1 1 1 1 1
Memory 
clg
for i = 1 to 20
isquare=i*i
Print isquare
color blue
rect isquare,isquare,i,i
next i
T ext output
Graphics output
PROGRAM
OUTPUT
 
 
 
Tejas: Next i is incremented by 1. The sequence is repeated till i = 20. When i>20 the repetition 
stops. [Memory i = 2 .......  i=20]
Moz: Very good. You have explained the repetition sequence very well. 
Jyoti: Instead of incrementing the value of i by 1 is it possible to increment i by more than one?
Moz: Yes. You can. For example you can write the repetition statement as follows:
Tejas: Wow. What a pattern! 
Moz: Change the step to 100 and see the effect.
Jyoti: When the step is incremented by 100, the sequence is repeated 3 times. 3 lines of blue and 
3 lines of red are drawn. 
Moz: Yes. Instead of incrementing by 1, the repetition count is incremented by the step.
PROGRAM
OUTPUT
Graphics output
# moire.kbs
clg
for t = 1 to 300 step 3
color red
line 0,0,300,t
color blue
line 0,0,t,300
next t
Tejas: The line statement has generated interesting graphics.
Moz: Right. Look at the lines closely  in the output of the program moire.kbs. 
Jyoti: They look crooked. The computer is not able to draw straight lines. The pattern looks like 
the print on our table cloth at home.
Moz: You are right. These patterns are used in textiles. The pattern is generated because the 
computer cannot display perfectly straight lines. It approximates a straight line by drawing the 
pixels in a stair step fashion. Such patterns are called moire patterns. 
Repetition of a block of statements - For statement
Info
Syntax
for variable = expr1 to expr2 
statement(s)
next variable
for variable = expr1 to expr2 step expr3
statement(s)
next variable
For •	 statement, executes a 
specified block of code a 
specified number of times, and 
keeps track of the value of the 
variable.
At the start of execution of for • 
loop, variable is assigned the 
value of expr1 and the specified 
block is executed.
if • step is not specified, 
variable will be incremented 
by 1 for the second and 
subsequent repetition of the   
specified block.
If step is specified •	 , variable will 
be incremented by expr3 for 
the second and subsequent 
repetition of the specified 
block.
For •	 loop terminates when the 
value of variable exceeds 
expr2.
PROGRAM
OUTPUT
for i = 20 to 25 
 Print  i + “square = ” + i*i
next i 
20 square = 400
21 square = 441
21 square = 484
23 square = 529
24 square = 576
25 square = 625
PROGRAM
OUTPUT
for i = 20 step -1 
 Print  i + “square = ” + i*i
next i 
25 square = 625
24 square = 576
23 square = 529
22 square = 484
21 square = 441
20 square = 400
PROGRAM
OUTPUT
for i = 20 to 25 step 5
 Print  i + “square = ” + i*i
next i 
20 square = 400
25 square = 625
t
t
..... next t
..... 
..... 
(Step command 
increments the 
value of ‘t’ by 
3).... next t
Inside the ‘for’ loop:
so on until ‘t’ becomes 
greater than 300
1
4
Memory
Page 3


Jyoti [after seeing the interesting graphics]: Using a repetitive mathematical sequence, we can easily 
draw interesting patterns.
Moz: Yes. Execute the program below, step by step, and understand how a sequence starts, is 
repeated and ends. This program uses the for statement.
Tejas: First the graphics output screen and the text output screen are cleared.
Jyoti: The variable i is assigned the value 1 at the start of the repetition. [Memory i = 1]
Tejas: The sequence to be repeated starts. Square of i is calculated and assigned to isquare. Then 
isquare is printed in text output area.  [Memory isquare = 1]
Jyoti: isquare is used for x and y coordinates in the rectangle statement. The length and breadth of 
the rectangle is set to i. A rectangle is output in the graphics output area. Rect 1,1,1,1
i
i
i
i
i
i
i
i
i
i
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
so on until i>10
1
2
3
4
5
6
7
8
9
10
1
4
9
16
25
36
49
64
81
100
Memory
Aim: In this lesson, you will learn:
- Control the execution of a program.
- Repeat and decision making statements.
- Managing lists with arrays.
BASIC Programming: 
Control and Repetition 
10
       if SP > CP
Profit=111
1 1 1 1 1
CP P C
1 1 1
1 1 1 1 1 1 1 1 1 1
Memory 
clg
for i = 1 to 20
isquare=i*i
Print isquare
color blue
rect isquare,isquare,i,i
next i
T ext output
Graphics output
PROGRAM
OUTPUT
 
 
 
Tejas: Next i is incremented by 1. The sequence is repeated till i = 20. When i>20 the repetition 
stops. [Memory i = 2 .......  i=20]
Moz: Very good. You have explained the repetition sequence very well. 
Jyoti: Instead of incrementing the value of i by 1 is it possible to increment i by more than one?
Moz: Yes. You can. For example you can write the repetition statement as follows:
Tejas: Wow. What a pattern! 
Moz: Change the step to 100 and see the effect.
Jyoti: When the step is incremented by 100, the sequence is repeated 3 times. 3 lines of blue and 
3 lines of red are drawn. 
Moz: Yes. Instead of incrementing by 1, the repetition count is incremented by the step.
PROGRAM
OUTPUT
Graphics output
# moire.kbs
clg
for t = 1 to 300 step 3
color red
line 0,0,300,t
color blue
line 0,0,t,300
next t
Tejas: The line statement has generated interesting graphics.
Moz: Right. Look at the lines closely  in the output of the program moire.kbs. 
Jyoti: They look crooked. The computer is not able to draw straight lines. The pattern looks like 
the print on our table cloth at home.
Moz: You are right. These patterns are used in textiles. The pattern is generated because the 
computer cannot display perfectly straight lines. It approximates a straight line by drawing the 
pixels in a stair step fashion. Such patterns are called moire patterns. 
Repetition of a block of statements - For statement
Info
Syntax
for variable = expr1 to expr2 
statement(s)
next variable
for variable = expr1 to expr2 step expr3
statement(s)
next variable
For •	 statement, executes a 
specified block of code a 
specified number of times, and 
keeps track of the value of the 
variable.
At the start of execution of for • 
loop, variable is assigned the 
value of expr1 and the specified 
block is executed.
if • step is not specified, 
variable will be incremented 
by 1 for the second and 
subsequent repetition of the   
specified block.
If step is specified •	 , variable will 
be incremented by expr3 for 
the second and subsequent 
repetition of the specified 
block.
For •	 loop terminates when the 
value of variable exceeds 
expr2.
PROGRAM
OUTPUT
for i = 20 to 25 
 Print  i + “square = ” + i*i
next i 
20 square = 400
21 square = 441
21 square = 484
23 square = 529
24 square = 576
25 square = 625
PROGRAM
OUTPUT
for i = 20 step -1 
 Print  i + “square = ” + i*i
next i 
25 square = 625
24 square = 576
23 square = 529
22 square = 484
21 square = 441
20 square = 400
PROGRAM
OUTPUT
for i = 20 to 25 step 5
 Print  i + “square = ” + i*i
next i 
20 square = 400
25 square = 625
t
t
..... next t
..... 
..... 
(Step command 
increments the 
value of ‘t’ by 
3).... next t
Inside the ‘for’ loop:
so on until ‘t’ becomes 
greater than 300
1
4
Memory
Jyoti: I want to write a program for the Profit and Loss flowchart. What is the syntax of If 
statement in Basic?      Scratch conditions
Tejas: Let us create a flowchart for writing a program to calculate profit and loss.
Tejas: The flowchart does not show what should be done if both CP and SP are equal. Let us use 
the else statement to take care of this condition.
Moz: Good. You must take care of all the conditions that are possible.
Jyoti: We can use comparison operators to compare CP and SP and find if it is profit, loss or the 
values are equal. 
Graphics – Drawing a line: line statement
Syntax
line start_x, start_y, finish_x, finish_y
Draw a line one pixel wide from the 
starting point to the ending point, 
using the current color.
PROGRAM
OUTPUT
clg 
line 0,0,1,255
line 255,255,1,0
line 1,255,255,255
Grapic output
(start x,
start y)
(finish x,
finish y)
1
The flowchart written by Tejas and Jyoti.
Flowchart: How to find profit or loss
Start
Read Cost price (CP)
Read Selling price (SP)
Is SP>CP
Is SP=CP
No
Stop
Print Profit
Yes
Profit= SP-CP
Yes
Print no profit 
or loss
Print Loss
No
Loss= CP-SP
if and if-else statements are used to check for a condition in a program. If the condition is true the set of instructions after if are executed. 
Otherwise, the set of instructions after else are executed.
1
Info
Page 4


Jyoti [after seeing the interesting graphics]: Using a repetitive mathematical sequence, we can easily 
draw interesting patterns.
Moz: Yes. Execute the program below, step by step, and understand how a sequence starts, is 
repeated and ends. This program uses the for statement.
Tejas: First the graphics output screen and the text output screen are cleared.
Jyoti: The variable i is assigned the value 1 at the start of the repetition. [Memory i = 1]
Tejas: The sequence to be repeated starts. Square of i is calculated and assigned to isquare. Then 
isquare is printed in text output area.  [Memory isquare = 1]
Jyoti: isquare is used for x and y coordinates in the rectangle statement. The length and breadth of 
the rectangle is set to i. A rectangle is output in the graphics output area. Rect 1,1,1,1
i
i
i
i
i
i
i
i
i
i
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
so on until i>10
1
2
3
4
5
6
7
8
9
10
1
4
9
16
25
36
49
64
81
100
Memory
Aim: In this lesson, you will learn:
- Control the execution of a program.
- Repeat and decision making statements.
- Managing lists with arrays.
BASIC Programming: 
Control and Repetition 
10
       if SP > CP
Profit=111
1 1 1 1 1
CP P C
1 1 1
1 1 1 1 1 1 1 1 1 1
Memory 
clg
for i = 1 to 20
isquare=i*i
Print isquare
color blue
rect isquare,isquare,i,i
next i
T ext output
Graphics output
PROGRAM
OUTPUT
 
 
 
Tejas: Next i is incremented by 1. The sequence is repeated till i = 20. When i>20 the repetition 
stops. [Memory i = 2 .......  i=20]
Moz: Very good. You have explained the repetition sequence very well. 
Jyoti: Instead of incrementing the value of i by 1 is it possible to increment i by more than one?
Moz: Yes. You can. For example you can write the repetition statement as follows:
Tejas: Wow. What a pattern! 
Moz: Change the step to 100 and see the effect.
Jyoti: When the step is incremented by 100, the sequence is repeated 3 times. 3 lines of blue and 
3 lines of red are drawn. 
Moz: Yes. Instead of incrementing by 1, the repetition count is incremented by the step.
PROGRAM
OUTPUT
Graphics output
# moire.kbs
clg
for t = 1 to 300 step 3
color red
line 0,0,300,t
color blue
line 0,0,t,300
next t
Tejas: The line statement has generated interesting graphics.
Moz: Right. Look at the lines closely  in the output of the program moire.kbs. 
Jyoti: They look crooked. The computer is not able to draw straight lines. The pattern looks like 
the print on our table cloth at home.
Moz: You are right. These patterns are used in textiles. The pattern is generated because the 
computer cannot display perfectly straight lines. It approximates a straight line by drawing the 
pixels in a stair step fashion. Such patterns are called moire patterns. 
Repetition of a block of statements - For statement
Info
Syntax
for variable = expr1 to expr2 
statement(s)
next variable
for variable = expr1 to expr2 step expr3
statement(s)
next variable
For •	 statement, executes a 
specified block of code a 
specified number of times, and 
keeps track of the value of the 
variable.
At the start of execution of for • 
loop, variable is assigned the 
value of expr1 and the specified 
block is executed.
if • step is not specified, 
variable will be incremented 
by 1 for the second and 
subsequent repetition of the   
specified block.
If step is specified •	 , variable will 
be incremented by expr3 for 
the second and subsequent 
repetition of the specified 
block.
For •	 loop terminates when the 
value of variable exceeds 
expr2.
PROGRAM
OUTPUT
for i = 20 to 25 
 Print  i + “square = ” + i*i
next i 
20 square = 400
21 square = 441
21 square = 484
23 square = 529
24 square = 576
25 square = 625
PROGRAM
OUTPUT
for i = 20 step -1 
 Print  i + “square = ” + i*i
next i 
25 square = 625
24 square = 576
23 square = 529
22 square = 484
21 square = 441
20 square = 400
PROGRAM
OUTPUT
for i = 20 to 25 step 5
 Print  i + “square = ” + i*i
next i 
20 square = 400
25 square = 625
t
t
..... next t
..... 
..... 
(Step command 
increments the 
value of ‘t’ by 
3).... next t
Inside the ‘for’ loop:
so on until ‘t’ becomes 
greater than 300
1
4
Memory
Jyoti: I want to write a program for the Profit and Loss flowchart. What is the syntax of If 
statement in Basic?      Scratch conditions
Tejas: Let us create a flowchart for writing a program to calculate profit and loss.
Tejas: The flowchart does not show what should be done if both CP and SP are equal. Let us use 
the else statement to take care of this condition.
Moz: Good. You must take care of all the conditions that are possible.
Jyoti: We can use comparison operators to compare CP and SP and find if it is profit, loss or the 
values are equal. 
Graphics – Drawing a line: line statement
Syntax
line start_x, start_y, finish_x, finish_y
Draw a line one pixel wide from the 
starting point to the ending point, 
using the current color.
PROGRAM
OUTPUT
clg 
line 0,0,1,255
line 255,255,1,0
line 1,255,255,255
Grapic output
(start x,
start y)
(finish x,
finish y)
1
The flowchart written by Tejas and Jyoti.
Flowchart: How to find profit or loss
Start
Read Cost price (CP)
Read Selling price (SP)
Is SP>CP
Is SP=CP
No
Stop
Print Profit
Yes
Profit= SP-CP
Yes
Print no profit 
or loss
Print Loss
No
Loss= CP-SP
if and if-else statements are used to check for a condition in a program. If the condition is true the set of instructions after if are executed. 
Otherwise, the set of instructions after else are executed.
1
Info
Syntax
if condition then
statement(s)
end if
if condition then
statement(s) 
else
statement(s) 
end if
The • if statement allows you to control 
if a program executes a section of 
code or not, based on whether a 
given condition is true or false.
The condition which is also referred • 
to as boolean condition can contain 
comparison operators or logical 
operators. (A table of the operators is 
given separately). The evaluation of 
the condition is either true or false.
At the start of the execution of • if 
statement the condition is evaluated. 
If the condition is  o true the block 
of statements following then  
are executed.
If the  condition  is  o false, the 
execution continues either in the 
else block (which is usually optional), 
or if there is no else branch, then 
the execution continues after the  
end if.
It is often customary to indent • 
the statements within the if or  
else block. 
Decisions – Execution branching: If, if-else statement
cls
input “ What is your age ” , myage
input “ What is your friend’s age? ” , 
friendage
if  myage = friendage then
Print  “ You and your friend of same age ”
endif
What is your age 13
What is your friend’s age? 
14
PROGRAM
OUTPUT
First Number 35
Second number 90
Computerji: Y es
PROGRAM
OUTPUT
CP
SP
Profit
876
987
111
Memory
CP
SP
Loss
567
500
67
Memory
The program written by Tejas and Jyoti.
Info
PROGRAM
OUTPUT
T ext output
Graphics output
T ext output
Graphics output
1 1 1
PROFIT
LOSS
Page 5


Jyoti [after seeing the interesting graphics]: Using a repetitive mathematical sequence, we can easily 
draw interesting patterns.
Moz: Yes. Execute the program below, step by step, and understand how a sequence starts, is 
repeated and ends. This program uses the for statement.
Tejas: First the graphics output screen and the text output screen are cleared.
Jyoti: The variable i is assigned the value 1 at the start of the repetition. [Memory i = 1]
Tejas: The sequence to be repeated starts. Square of i is calculated and assigned to isquare. Then 
isquare is printed in text output area.  [Memory isquare = 1]
Jyoti: isquare is used for x and y coordinates in the rectangle statement. The length and breadth of 
the rectangle is set to i. A rectangle is output in the graphics output area. Rect 1,1,1,1
i
i
i
i
i
i
i
i
i
i
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
isquare
so on until i>10
1
2
3
4
5
6
7
8
9
10
1
4
9
16
25
36
49
64
81
100
Memory
Aim: In this lesson, you will learn:
- Control the execution of a program.
- Repeat and decision making statements.
- Managing lists with arrays.
BASIC Programming: 
Control and Repetition 
10
       if SP > CP
Profit=111
1 1 1 1 1
CP P C
1 1 1
1 1 1 1 1 1 1 1 1 1
Memory 
clg
for i = 1 to 20
isquare=i*i
Print isquare
color blue
rect isquare,isquare,i,i
next i
T ext output
Graphics output
PROGRAM
OUTPUT
 
 
 
Tejas: Next i is incremented by 1. The sequence is repeated till i = 20. When i>20 the repetition 
stops. [Memory i = 2 .......  i=20]
Moz: Very good. You have explained the repetition sequence very well. 
Jyoti: Instead of incrementing the value of i by 1 is it possible to increment i by more than one?
Moz: Yes. You can. For example you can write the repetition statement as follows:
Tejas: Wow. What a pattern! 
Moz: Change the step to 100 and see the effect.
Jyoti: When the step is incremented by 100, the sequence is repeated 3 times. 3 lines of blue and 
3 lines of red are drawn. 
Moz: Yes. Instead of incrementing by 1, the repetition count is incremented by the step.
PROGRAM
OUTPUT
Graphics output
# moire.kbs
clg
for t = 1 to 300 step 3
color red
line 0,0,300,t
color blue
line 0,0,t,300
next t
Tejas: The line statement has generated interesting graphics.
Moz: Right. Look at the lines closely  in the output of the program moire.kbs. 
Jyoti: They look crooked. The computer is not able to draw straight lines. The pattern looks like 
the print on our table cloth at home.
Moz: You are right. These patterns are used in textiles. The pattern is generated because the 
computer cannot display perfectly straight lines. It approximates a straight line by drawing the 
pixels in a stair step fashion. Such patterns are called moire patterns. 
Repetition of a block of statements - For statement
Info
Syntax
for variable = expr1 to expr2 
statement(s)
next variable
for variable = expr1 to expr2 step expr3
statement(s)
next variable
For •	 statement, executes a 
specified block of code a 
specified number of times, and 
keeps track of the value of the 
variable.
At the start of execution of for • 
loop, variable is assigned the 
value of expr1 and the specified 
block is executed.
if • step is not specified, 
variable will be incremented 
by 1 for the second and 
subsequent repetition of the   
specified block.
If step is specified •	 , variable will 
be incremented by expr3 for 
the second and subsequent 
repetition of the specified 
block.
For •	 loop terminates when the 
value of variable exceeds 
expr2.
PROGRAM
OUTPUT
for i = 20 to 25 
 Print  i + “square = ” + i*i
next i 
20 square = 400
21 square = 441
21 square = 484
23 square = 529
24 square = 576
25 square = 625
PROGRAM
OUTPUT
for i = 20 step -1 
 Print  i + “square = ” + i*i
next i 
25 square = 625
24 square = 576
23 square = 529
22 square = 484
21 square = 441
20 square = 400
PROGRAM
OUTPUT
for i = 20 to 25 step 5
 Print  i + “square = ” + i*i
next i 
20 square = 400
25 square = 625
t
t
..... next t
..... 
..... 
(Step command 
increments the 
value of ‘t’ by 
3).... next t
Inside the ‘for’ loop:
so on until ‘t’ becomes 
greater than 300
1
4
Memory
Jyoti: I want to write a program for the Profit and Loss flowchart. What is the syntax of If 
statement in Basic?      Scratch conditions
Tejas: Let us create a flowchart for writing a program to calculate profit and loss.
Tejas: The flowchart does not show what should be done if both CP and SP are equal. Let us use 
the else statement to take care of this condition.
Moz: Good. You must take care of all the conditions that are possible.
Jyoti: We can use comparison operators to compare CP and SP and find if it is profit, loss or the 
values are equal. 
Graphics – Drawing a line: line statement
Syntax
line start_x, start_y, finish_x, finish_y
Draw a line one pixel wide from the 
starting point to the ending point, 
using the current color.
PROGRAM
OUTPUT
clg 
line 0,0,1,255
line 255,255,1,0
line 1,255,255,255
Grapic output
(start x,
start y)
(finish x,
finish y)
1
The flowchart written by Tejas and Jyoti.
Flowchart: How to find profit or loss
Start
Read Cost price (CP)
Read Selling price (SP)
Is SP>CP
Is SP=CP
No
Stop
Print Profit
Yes
Profit= SP-CP
Yes
Print no profit 
or loss
Print Loss
No
Loss= CP-SP
if and if-else statements are used to check for a condition in a program. If the condition is true the set of instructions after if are executed. 
Otherwise, the set of instructions after else are executed.
1
Info
Syntax
if condition then
statement(s)
end if
if condition then
statement(s) 
else
statement(s) 
end if
The • if statement allows you to control 
if a program executes a section of 
code or not, based on whether a 
given condition is true or false.
The condition which is also referred • 
to as boolean condition can contain 
comparison operators or logical 
operators. (A table of the operators is 
given separately). The evaluation of 
the condition is either true or false.
At the start of the execution of • if 
statement the condition is evaluated. 
If the condition is  o true the block 
of statements following then  
are executed.
If the  condition  is  o false, the 
execution continues either in the 
else block (which is usually optional), 
or if there is no else branch, then 
the execution continues after the  
end if.
It is often customary to indent • 
the statements within the if or  
else block. 
Decisions – Execution branching: If, if-else statement
cls
input “ What is your age ” , myage
input “ What is your friend’s age? ” , 
friendage
if  myage = friendage then
Print  “ You and your friend of same age ”
endif
What is your age 13
What is your friend’s age? 
14
PROGRAM
OUTPUT
First Number 35
Second number 90
Computerji: Y es
PROGRAM
OUTPUT
CP
SP
Profit
876
987
111
Memory
CP
SP
Loss
567
500
67
Memory
The program written by Tejas and Jyoti.
Info
PROGRAM
OUTPUT
T ext output
Graphics output
T ext output
Graphics output
1 1 1
PROFIT
LOSS
Comparison operators
Comparison Operators
In a program, we often need to compare two values to decide what to do. A comparison 
operator (ex: <, >, <=) works with two values and returns true or false based on the result  
of the comparison.
Jyoti: Let us see if we can display an image in the graphics output area. I have drawn images for 
profit and loss. 
Tejas: We can use imgload. This is very easy we have to just provide x, y coordinates where we 
want the image displayed and the image file name. Let us also check how to display a caption for 
the image in graphics area.
Jyoti: Displaying text also has similar syntax to imgload. In place of file name we have to provide 
the text in quotes. 
Comparative operators Description Example
expr1 < expr2 Evaluates to True if value of expr1 is less than value of 
expr2, else to False.
2<4 is True
expr1 > expr2 Evaluates to True if value of expr1 is greater than value 
of expr2, else to False.
(2+5)>(3+4) is 
False
expr1 = expr2 Evaluates to True if value of expr1 is equal to value of 
expr2 else to False.
298=298 is True
expr1 >= expr2 Evaluates to True if value of expr1 is greater than or equal 
to value of expr2, else to False.
2>=4 is False
expr1 <= expr2 Evaluates to True if value of expr1 is less than or equal to 
value of expr2, else to False.
2<=4 is True
expr1 <> expr2 Evaluates to True if value of expr1 is not equal to value 
of expr2 else to False.
2<>4 is True
Syntax
imgload x, y, filename    
imgload x, y, scale, filename
imgload x, y, scale, rotation, filename
Imgload reads the image in the • 
file specified in the filename 
and displays it on the graphics 
output area. The x, y coordinates 
specify the location of the 
center of the image, where the 
image should be displayed in 
the graphics output area.  
Many of the image file formats • 
are recognized by the program. 
Some of these formats are bmp, 
png, gif, jpg and jpeg.
Scaling •	 and rotation is optional. 
Scaling is used to resize  o
the image. Note that scale 
is specified by the decimal 
scale where 1 is full size.  
The image can be rotated   o
around it’s center by 
specifying how far to rotate 
by specifying the angle  
(0 to 360).
PROGRAM
OUTPUT
Grapic output
PROGRAM
OUTPUT
Grapic output
PROGRAM
OUTPUT
Grapic output
Graphics – Loading an image imgload statement
Info Info
Read More
26 docs|14 tests

Top Courses for Class 7

26 docs|14 tests
Download as PDF
Explore Courses for Class 7 exam

Top Courses for Class 7

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Important questions

,

practice quizzes

,

past year papers

,

Summary

,

Textbook: Basic Programming- Control and Repetition | Computer Science for Class 7

,

Previous Year Questions with Solutions

,

mock tests for examination

,

shortcuts and tricks

,

Viva Questions

,

Textbook: Basic Programming- Control and Repetition | Computer Science for Class 7

,

video lectures

,

Objective type Questions

,

pdf

,

Textbook: Basic Programming- Control and Repetition | Computer Science for Class 7

,

Free

,

ppt

,

Exam

,

Semester Notes

,

MCQs

,

study material

,

Sample Paper

,

Extra Questions

;