0% found this document useful (0 votes)
8 views3 pages

Basic Programming II (One Dimensional Array)

The document covers the basics of syntax and semantics in programming, explaining their roles in code validity and meaning. It also introduces one-dimensional arrays, demonstrating their creation and manipulation through examples of input, output, and arithmetic operations. Key points include the importance of syntax for compilation and semantics for logical correctness.

Uploaded by

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

Basic Programming II (One Dimensional Array)

The document covers the basics of syntax and semantics in programming, explaining their roles in code validity and meaning. It also introduces one-dimensional arrays, demonstrating their creation and manipulation through examples of input, output, and arithmetic operations. Key points include the importance of syntax for compilation and semantics for logical correctness.

Uploaded by

bulusj517
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

WEEK 8

BASIC PROGRAMMING III (ONE DIMENSIONAL ARRAY)

Syntax refers to the set of rules and structures that define the correct arrangement
of symbols and keywords in a programming language. It determines how the code
must be written for it to be valid and recognizable by the compiler or interpreter.

1. Key Points:
a. Grammar Rules: Specifies the proper arrangement of tokens (keywords,
operators, identifiers) in a program.
b. Syntax Errors: Occur when the code deviates from these rules, such as missing
punctuation, incorrect keywords, or misaligned braces. These errors prevent
the program from compiling or running.
Examples:
Correct: `PRINT "Hello, World!"`
Incorrect: `PRINT "Hello, World!` (missing closing quotation mark)
SEMANTICS: Semantics deals with the meaning of the code. It defines what the
program is supposed to do when executed, interpreting the syntax according to
the rules and logic of the language.
Key Points
Meaning of Constructs: Focuses on what each statement or construct is intended
to accomplish.
Semantic Errors: Occur when the code is syntactically correct but logically
flawed, leading to unexpected or incorrect behaviour. These errors do not prevent
compilation but result in incorrect program output.
Examples:
Syntax is Correct but Semantically Incorrect:
LET A = 5
LET B = 0
LET C = A / B
PRINT C
This code will not compile if the language supports division by zero checks, or it
may produce an error or undefined result if not handled.
Relationship Between Syntax and Semantics: Syntax First: The compiler or
interpreter first checks for syntax errors. If the syntax is correct, it then processes
the semantics.
ONE DIMENSIONAL ARRAY
An array is a list of variables of the same datatype. Arrays are useful for
organizing multiple variables. To create an array, use the DIM (dimension)
command.

Example of Code without an Array


10 a = 5
20 b = 10
30 c = 15
40 Print a, b, c
50 END

Example of Code with an Array


10 DIM nos(3)
20 nos(1) = 5
30 nos(2)=10
40 nos(3) = 15
50 Print nos(1), nos(2), nos(3)

List of Operations on Array Arrays can be manipulated in the following


ways:
1. Input of an Array: This example illustrates how to perform arithmetic
operation with values stored in an array.
10 DIM ages(5)
20 ages(1) = 12
30 ages(2) = 15
40 ages(3) = 11
50 ages(4) = 10
60 ages(5) = 12

2. Output of an Array: This example illustrates how to output values stored in an


array. The code below is an extension of the example above.
10 DIM ages(5)
20 ages(1) = 12
30 ages(2) = 15
40 ages(3) = 11
50 ages(4) = 10
60 ages(5) = 12
70 PRINT ages(1), ages(2), ages (3), ages(4), ages(5)
3. Arithmetic on Array: This example illustrates how to perform arithmetic
operation with values stored in an array.
10 DIM ages(5)
20 ages(1) = 12
30 ages(2) = 15
40 ages(3) = 11
50 ages(4) = 10
60 ages(5) = 12
70 Total = ages(1) + ages (2) + ages(3) + ages(4)+ ages(5)
80 Average Total/5
90 Print "The Average of the Values in the array is ",Average

You might also like