0% found this document useful (0 votes)
16 views12 pages

Subscript Expressions 1

Uploaded by

gideon.aleburu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views12 pages

Subscript Expressions 1

Uploaded by

gideon.aleburu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Subscript Expression and

Control Statement
By
Tunji-Bakare Hannah EDU2412544
Adegoke Rasheedah EDU2412547
ADENIKA Olamide Isaac EDU2012722
CONTENT:
• What are Subscript Expressions?
• Syntax and Usage in Programming
• What are Control Statements?
• Types of Control Statements
• Combining Subscript Expressions
with Control Statements
• Real-world Examples
• Summary
What is a Subscript Expression?

• A subscript expression refers to accessing

elements in a collection or data structure using an

index or key.

• Found in arrays, lists, tuples, strings,

dictionaries, etc.

• Helps in retrieving, modifying, or assigning

values.

Example (Python):

my_list = [10, 20, 30]

print(my_list[1]) # Output: 20
Syntax of Subscript Expressions

• General Syntax: collection[index]

• Index can be:

• An integer (for lists/arrays)

• A key (for dictionaries)

• A string index (for string characters)

Example (Dictionary):

student = {"name": "John", "age": 20}

print(student["name"]) # Output: John

Slide 5: Common Data Structures Using Subscripts


• List/Array: list[index]

• Tuple: tuple[index]

• String: string[index]

• Dictionary (Python): dict[key]

• 2D List or Matrix: matrix[row][column]

What are Control Statements?

• Statements that control the flow of execution

in a program.

• Determine when and how blocks of code are

executed.

Three Major Types:


1. Conditional Statements

2. Looping Statements

3. Jump Statements

Conditional Statements

Used to execute code only if certain conditions are

true.

Examples:

• if

• if...else

• if...elif...else

Python Example:

x = 10

if x > 5:
print("x is greater than 5")

Looping Statements

Used to repeat a block of code.

Types:

• for loop

• while loop

Python Example:

for i in range(3):

print(i)

Jump Statements
Used to control loop execution.

Types:

• break – exits loop

• continue – skips iteration

• pass – placeholder for future code

Python Example:

for i in range(5):

if i == 3:

break

print(i)

Using Subscript in Control Statements


Subscript expressions are often used inside control

statements for dynamic behavior.

Example:

names = ["Alice", "Bob", "Charlie"]

for i in range(len(names)):

if names[i] == "Bob":

print("Found Bob")

Example – Search with Subscript + Control

Goal: Search for a value in a list.

numbers = [3, 7, 1, 9, 5]
target = 9

for i in range(len(numbers)):

if numbers[i] == target:

print("Found at index:", i)

break

Real-world Applications

• Data Analysis: Iterating over rows and

columns in data tables

• Web Development: Accessing form values or

API responses

• Game Development: Checking game board or

player status
• AI/ML: Working with tensors and matrices

Summary
• Subscript expressions allow accessing
elements via indices or keys
• Control statements manage the logical flow
of programs
• Used together, they allow powerful data
handling and program logic
REFERENCES
1. “Python Crash Course” by Eric Matthes
• Covers subscript expressions
(indexing/slicing) and control statements in
Python.
• ISBN: 978-1593279288
2. “Introduction to the Theory of Computation”
by Michael Sipser
• Offers foundational concepts on control flow
and computation theory.
3. “C Programming Language” by Brian W.
Kernighan and Dennis M. Ritchie
• Introduces control statements like if, switch,
for, and arrays (subscripted variables).

You might also like