You are on page 1of 5

# LOOPS

======================

I. BRANCHING LOOPS
1.IF..ELSE..ENDIF.
2.IF..ELSEIF...ELSEIF...ELSE...ENDIF.
3.CASE...ENDCASE.

II.LOOPING LOOPS
1.DO...ENDDO.
2.WHILE..ENDWHILE
================================
branching loops

1.IF..ELSE..ENDIF.

syntax:

if <condition>.
<stmt block>.
else.
<stmt block>.
endif.

## parameters: numb type i.

if numb > 0.
write:/ '+ve number entered'.
else.
write:/ '-ve number entered'.
endif.

if..elseif...elseif...else...endif
------------------------------------
syntax:
if <condition>.
<stmt block>.
elseif <condition>.
<stmt block>.
elseif <condition>.
<stmt block>.
...
else.
<stmt block>.
endif.

compute : uses BODMAS principle in maths which is used for formulae calculation
*program for if...elseif...elseif...elseif...else...endif

sub2 type i,
sub3 type i.

## data: tot type i.

if sub1 > 100 or sub2 > 100 or sub3 > 100.
message e333(555) with 'do not give more then 100 marks'.
else.
compute tot = ( sub1 + sub2 + sub3 ) / 3.
if tot <= 40.
write:/ 'fail'.
elseif tot > 40 and tot <= 50.
write:/ 'third'.
elseif tot > 50 and tot <= 60.
write:/ 'second'.
elseif tot > 60 and tot <= 70.
write:/ 'first'.
else.
write:/ 'distinction'.
endif.
endif.

=======================================
<= le
>= ge
<> ne
= eq

or and
====================================
case...endcase

case <f>.
when <f1>.
<1st statment block>. "if f = f1, it will execute 1st statement block
when <f2>.
<2nd statement block>. "if f = f2 , it will execute 2nd statement block
when <f3>.
<3rd statement block>. " if f = f3, it will execute 3rd statement block
when others.
<statement block>.
endcase.

## case is more faster then if..else..endif.

case is case-sensitive (when case should be given in capitals)
*case...endcase
parameters: week type i.

CASE WEEK.
WHEN 1.
WRITE:/ 'SUN'.
WHEN 2.
WRITE:/ 'MON'.
WHEN 3.
WRITE:/ 'TUE'.
WHEN 4.
WRITE:/ 'WED'.
WHEN 5.
WRITE:/ 'THU'.
WHEN 6.
WRITE:/ 'FRI'.
WHEN 7.
WRITE:/ 'SAT'.
WHEN OTHERS.
WRITE:/ 'NO WEEK DAY EXISTS'.
ENDCASE.
===============================

## PARAMETERS : GIFT(30) TYPE C.

WHEN 'BIKE'. "BIKE IS TO GIVEN IN CAPITALS ONLY
WHEN 'GOLD'.
WRITE:/ 'YOUR CHOICE IS DDAMAS GOLD'.
WHEN OTHERS.
ENDCASE.
=====================================

LOOPING LOOPS

DO...ENDDO

SYNTAX:
DO <VALUE > TIMES.
<STMT BLOCK>.
ENDDO.

*PRG
DO 5 TIMES.
WRITE:/ 'RAJ'.
ENDDO.

## SY-INDEX IS USED IN DO..LOOP TO KNOW THE ITERATION OF DO...LOOP

*PRG
DO 5 TIMES.
WRITE:/ SY-INDEX.
ENDDO.

*PRG
DO 5 TIMES.
IF SY-INDEX = 1.
WRITE:/ 'RAJ'.
ELSEIF SY-INDEX = 2.
WRITE:/ 'HARI'.
ELSEIF SY-INDEX = 3.
WRITE:/ 'LATA'.
ELSE.
WRITE:/ 'NO-NAME'.
ENDIF.
ENDDO.

*PRG
DO.
WRITE:/ 'RAJ'.
ENDDO.
THIS IS A RUNTIME ERROR
TO AVOID IT WE USE STOP/EXIT/CONTINUE

*PRG
DO.
WRITE:/ 'RAJ'.
EXIT.
ENDDO.
WRITE:/ 'LATA'.

RESULT:
RAJ
LATA

*PRG
DO.
WRITE:/ 'RAJ'.
STOP.
ENDDO.
WRITE:/ 'LATA'.

RESULT: RAJ

WHILE...ENDWHILE
WHILE <CONDITION>.
<STMT BLOCK>.
CNT = CNT + 1.
ENDWHILE.

## *PROGRAM FOR WHILE...ENDWHILE

DATA: NUM TYPE I VALUE 1.

WRITE:/ NUM.
NUM = NUM + 1.
ENDWHILE.

## PROGRAMS AS ASSIGNMENT ON LOOPS

================================================
ASSIGNMENTS ON LOOPS
===============================================

SAY 2 AS INPUT
2 X 1 = 2
...
2 X 10 = 20.

## 2.WRITE A PROGRAM FOR SWAPPING TWO NUMBERS

INPUT A 50
B 60

OUTPUT A 60
B 50
3.WRITE A PROGRAM FOR FACTORIAL OF A NUMBER
4! = 4 * 3 * 2 * 1 = 24.

## 4.WRITE A PROGRAM FOR A NUMBER IS PRIME, ODD, EVEN

3 : ODD AND PRIME.
PRIME : DIVISIBLE BY ONE AND ITSELF.
EVEN: DIVISIBLE BY 2

7
OUTPUT:
*******
******
*****
****
***
**
*

## 6.ENTER A STRING 'ECHO'

OUTPUT SHOULD DISPLAY

E
EC
ECH
ECHO
ECH
EC
E

7.CALCULATE SI = P * N * R / 100.

## HINT: DATA: PAMT TYPE P DECIMALS 2.

============================================
NEXT CLASS: STRINGS

## ANYTHING IN A SINGLE QUOTE IS A STRING ' '

OPERATIONS ON THE STRINGS
1.SHIFT
2.STRLEN
3.CONDENSE
4.SPLIT
5.CONCATENATE
6.MOVE
7.REPLACE
8.TRANSLATE
9.OVERLAY
10.SEARCH
===========================

## MODULARIZATION TECHNIQUES (VVIMP) MONDAY

1.INCLUDE
2.SUBROUTINES
3.FUNCTION MODULES
4.MACROS

=====================================