Paper 2 Part 2 (Programming Structures)
Paper 2 Part 2 (Programming Structures)
You should understand the difference between Simple Logic, Complex Logic and Nested IF Statements.
PRINT “enter a positive number”
INPUT number This is a simple condition
If number > 0 In which case it is only determining is the
if number > 10 number is positive.
then
print “this number is greater than 10” This is a nested if statement as it is part
else if number>=5 and number<=10 of another if statement (i.e. number>0).
then
print “this number is between 5 and 10 (inclusive)” This is a complex condition as it is taking
else in account of two conditions.
print “this number is less then 5” (number>=5 and number<=10) and since
else there is an “and” operator in between the
print “this number is not positive” two condition, both sub-statements have
to be true for this statement to be true.
Case…OF…OTHERWISE…ENDCASE
input choice
case of choice A variable “choice” will hold some value which
1: print “Have fun” is to be investigated and only one statement is
2: print “good luck” to be executed based on the contents of choice.
3: print “good night” Of the input is among 1..4 then the
4: print “good bye” corresponding statement will execute.
otherwise: However, if anything else in the “choice” then
Print “you have not selected a valid option” the default condition will execute.
end case
Loops:-
We will be solving the following problem using different
types of loops:-
“take 10 numbers as input and output the largest
number”
FOR…TO…NEXT…ENDFOR REPEAT…UNTIL WHILE…DO…ENDWHILE
Arrays are data structures that store the same type of data usually in random order.
Temp ßMyList[6]
MyList[6]ßMyList[3]
MyList[3]ßTemp
Swapping two values in an array
FOR count 1 to 7
PRINT MyList[count]
NEXT
END FOR //index position changes from count 1 to 7
//and prints all elements in array. 25,34,98…