Vous êtes sur la page 1sur 3

CONDITIONAL STATEMENTS

- responsible in checking whether a given expression is true or not before


performing a set of statements. In order for these statements to be executed, the
condition or set of conditions must first be satisfied.
- requires the use of different logical and relational operators.
IF (EXPRESSION / CONDITION)
STATEMENT1;
ELSE
STATEMENT2;
* Else Statement is added if a statement or set of statements must be done once
the expression is not true or the condition is not satisfied.
ITERATIVE OR LOOP STATEMENTS
- Signify repetition of a statement or set of statements.
- While, Do- while, For
- Loop statements are used to control the flow of instructions in a program. A certain
condition is evaluated before any statement in the loop can be performed.
1.) While loop
The expression is analyzed first.
while( expression )
{ statement1;
statement2;
statementN;
}
2.) Do-While
The statements will be performed first before the expression will be evaluated.
do
{ statement1;
statement2;
statemnetN;
}
while ( expression);
3.) For Loop
It takes the general form.
for ( initializing_list; condiotion; altering_list)
{ statement1;
statement2;
statementN;
}

FUNCTIONS
- are subroutines containing a statement or collection of statements that perform a
certain task.
FORMAT STRUCTURE:
Function_name ( )
{ statement1;
Statement2;
statementN;
}
FUNCTION TYPE:
GENERAL SYNTAX is function_name needed only when that function is defined
after main ( ).
This is done so that the compiler can ascertain that such function exist.
PASSING BY VALUE done successively in such a way that the value of the first
identifier being sent is stored in the first receiving variable; the value of the next
identifier being sent is stored in the second receiving variable, and so on.
ARGUMENTS the called function must then be able to receive the values of the
actual parameters passed to it by individually declaring these values.
returned_type function_name ( var1, var2,varN)
RETURN causes an instant exit from the function being called and eventually
causes program execution to return to the calling function.
return ( value );
return ( expression );
VOID is used instead of any particular data type. if the called function is not to
receive any value, void can be written inside the parentheses in the function header
line , or merely nothing at all.
Void function_name ( void )
Void function_name ( )
Void function_name ( int y )
Int function_name (void)
Int function_name ( )
2 FORMS OF PPASSING PARAMETERS
1. Passing by value - it gives a copy of the value of such argument to be called
function, when the called function is executed, the values passed to it can be
changed without affecting the original values of the variables in the calling function.

2. Passing by reference the address of the argument being passed is actually


the one being sent to the called function. Any alteration to the value of the received
parameter will alter the original value in the calling function.

Vous aimerez peut-être aussi