Site pages
Current course
Participants
General
Topic 1
Topic 2
Topic 3
Topic 4
Topic 5
Topic 6
Topic 7
Topic 8
Topic 9
Topic 10
Topic 11
Topic 12
Topic 13
Topic 14
Topic 15
Topic 16
Topic 17
Topic 18
Topic 19
Topic 20
Topic 21
Topic 22
Topic 23
Topic 24
Topic 25
Topic 26
Topic 27
Topic 28
Topic 29
Topic 30
Topic 31
Topic 32
Topic 33
Topic 34
Topic 35
The IF Statement
This statement helps in transferring the control of program execution from one part of the program to another depending on some test-condition. There are two types Its format is n – is the statement number test-condition – may be relational or logical expression. When the IF-THEN statement is executed in a program, the test-condition is tested. If the test-condition is true, control of program execution is transferred to statement labeled n. If the test-condition is False, the statement immediately following the IF-THEN statement is executed. Eg : 5 IF A>10 THEN 125 Program Given a set of 6 values as -5, 2, 6, -1.1, 0, 4 Develop a program that computes the sum of the values greater than zero. 10 DATA -5, 2, 6, -1.1, 0, 4 20 LET N=0 25 LET S=0 30 READ A 40 LET N = N+1 50 IF A<=0 THEN 70 60 LET S=S+A 70 IF N<6 THEN 30 80 PRINT “SUM=”;S 90 STOP 100 END Output SUM=12 2) IF-THEN-ELSE statement This is more general form of IF statement. Its syntax is where n1 and n2 are labels of other statements. When the test-condition is true, statement labeled n1is executed. However when the test-condition is false, statement n2 is executed. Eg: 60 IF A<> B THEN 100 ELSE 200 |
Last modified: Wednesday, 18 January 2012, 10:48 PM