Statements inside sequential control constructs are executed sequentially.
if-else Statement : The if-else statement is the general form of selection statement.
case Statement : The case statement provides for multi-way branching.
repeat loop : Repeat statements can be used to repeat the execution of a statement or statement block a fixed number of times.
for loop : The for construct can be used to create loops.
while loop : The loop iterates while the condition is true.
do-while : condition is checked after loop iteration.
foreach :ech construct specifies iteration over the elements of an single dimensional fixed-size arrays, dynamic arrays and SmartQs.
Loop Control : The break and continue statements are used for flow control within loops.
EXAMPLE : if program main { integer i;
i = 20; if( i == 20) printf(" I is equal to %d ",i); else printf(" I is not equal to %d ",i);
} RESULTS
I is equal to 20
EXAMPLE : case and repeat program main { integer i;
repeat(10){
i = random(); case(1) {
(i<0) :printf(" i is less than zero i==%d\n",i);
(i>0) :printf(" i is grater than zero i=%d\n",i);
(i == 0):printf(" i is equal to zero i=%d\n",i);
}
}
} RESULTS
i is grater than zero i=69120
i is grater than zero i=475628600
i is grater than zero i=1129920902
i is grater than zero i=773000284
i is grater than zero i=1730349006
i is grater than zero i=1674352583
i is grater than zero i=1662201030
i is grater than zero i=2044158707
i is grater than zero i=1641506755
i is grater than zero i=797919327
EXAMPLE : forloop program for_loop
{ integer count, i; for(count = 0, i=0; i*count<50; i++, count++) printf("Value i = %0d\n", i);
}
RESULTS
Value i = 0
Value i = 1
Value i = 2
Value i = 3
Value i = 4
Value i = 5
Value i = 6
Value i = 7
EXAMPLE : whileloop program while_loop{ integer operator=0; while (operator<5){
operator += 1; printf("Operator is %0d\n", operator);
}
} RESULTS
Operator is 1
Operator is 2
Operator is 3
Operator is 4
Operator is 5
EXAMPLE : dowhile program test
{ integer i = 0;
do
{ printf("i = %0d \n", i);
i++;
} while (i < 10);
} RESULTS
i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
i = 6
i = 7
i = 8
i = 9
EXAMPLE : foeach program example{ string names[$]={"Hello", "Vera"}; foreach (names, i) { printf("Value at index %0d is %0s\n", i, names[i]);
}
} RESULTS
Value at index 0 is Hello
Value at index 1 is Vera
EXAMPLE : randcase program rand_case{ integer i; repeat(10){ randcase
{
10: i=1;
20: i=2;
50: i=3;
} printf(" i is %d \n",i);}
} RESULTS
i is 3
i is 2
i is 3
i is 3
i is 3
i is 3
i is 1
i is 1
i is 1
i is 2