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

Chapter – 10 Control Statements in Small Basic

Control statements are used to change the flow of execution of the statements of a program, by
repeating or skipping a few statements, subject to a given condition. They are very helpful in making
decisions at run time.

There are three categories of Control Statements :

 Branching
 Looping
 Subroutines

Branching Statements

Branching statements are


used when a decision has
the result between the
two alternatives – “Yes”
and “No” result.

If Then Statement

The If Then Statement is


a branching statement
used to take decisions
based on comparisons. It
checks only the “True”
Condition of the program
and comes to an end.

Syntax :

If <Condition> Then

<Statements>

EndIf

Example :

If number >= 0 Then

Textwindow.writeline(“Number is positive”)

Endif
Example:

If Then Else Statement

The If Then Else statement is another branching statement, also called the Bi – Directional decision-
making statement, which is executes both the statements i.e. of both the True and False conditions.

Syntax:

If <Condition> Then

<Statement 1>

Else

<Statement 2>

EndIf

Example:

If number >= 0 Then

Textwindow.writeline(“Number is positive”)

Else

Textwindow.writeline(“Number is negative”)

Endif

The Elseif ladder

The Elseif ladder is used to check multiple conditions in a program.

The Goto statements

The Goto statement is an unconditional transfer control.It is used to transfer the program control
from one statement to another in a program.

Syntax:

Goto <Label>

Example :

Goto Start

Start is a label.

A label in a programming language is a sequence of characters that identifies a location within a


program.
Labels take the form of an identifier often followed by a colon (:)

Example :

A=1

Start :

B=A*A

Textwindow.writeline(B)

A=A+1

Goto Start

Goto with If Then

Goto with If then is used when a decision has to made about where the program control should go
next.

Syntax :

Label :

If <Condition> Then

<Statement(s)>

Goto Label

EndIf

Example :

J=0

Start :

J=j+1

If ( j < 10 ) Then

Goto Start

EndIf

You might also like