0% found this document useful (0 votes)
20 views1 page

Understanding Loops and Subroutines in Programming

This lesson covers the while and for loops, explaining that the while loop is a pre-test condition control loop while the for loop is a post-test count control loop. It also introduces sub-routines, which are independent parts of a program performing specific tasks, categorized into functions that return values and procedures that do not. Examples of both functions and procedures are provided to illustrate their syntax and usage.

Uploaded by

dihoncho.pro
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)
20 views1 page

Understanding Loops and Subroutines in Programming

This lesson covers the while and for loops, explaining that the while loop is a pre-test condition control loop while the for loop is a post-test count control loop. It also introduces sub-routines, which are independent parts of a program performing specific tasks, categorized into functions that return values and procedures that do not. Examples of both functions and procedures are provided to illustrate their syntax and usage.

Uploaded by

dihoncho.pro
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

LESSON 3

The while loop : it is the pre-test condition control loop.


Synthax:
While (condition) do
Action(s);
Endwhile

The for loop : it is a post-test count control loop

Sub-routine
It is a sub problem. A sub-problem is an independent part of a program that performs a specific
task, sub-routines are of two types. Which are:
Function and Procedure

1. Procedure :
A procedure is a sub -routines that does not return a value . a function on the other hand perform a
specitic task and returns a value .
A sub -routines is divided into two parts namely the header also known as signature or prototype and
the body
An example in writing fuctions:
a = 0; b = 20
int sum( int a, int b){
return a+b;
}
Printf(“sum of %d and %d is %d\n”, a,b,sum(a,b);
An example of a procedure:
Int a= 10, b=20, c;
Void sim(int a, int b){
C = a+b;
)
Sum (a,b);
Printf(“%d,c);

You might also like