Inelec Lessons Officie-Introduction Programming
Inelec Lessons Officie-Introduction Programming
Dr. F. Kerouh
Electronics Department
IGEE, UMBB
III.2 Iteration
– while (expr) { … } zero or more iterations
– do … while (expr) at least one iteration
– for ( init ; valid ; next ) { … }
III.3 Jump
– goto label
2015-2016
Chap 3. Introduction to programming and 3
C language ©
Outlines
III.1. 1 Introduction to Decision Making Statements
III.1. 2 If statement
Examples
Example 2:
if (grade>=90)
{
printf("\nYour grade is %d",grade);
printf("\nCongratulations!");
}
Example 3:
if (nbr1>=nbr2) if (( nbr1>=nbr2 ) && ( nbr1>=nbr3) )
if (nbr1>=nbr3) printf(“%d is the greater number”,nbr1);
printf(“%d is the greater number“,nbr1);
This is possible by
nesting if-else statements
together to make what is
called an if-else ladder.
2015-2016
Chap 3. Introduction to programming and 10
C language ©
III.1. 3 switch statement
It is a better way of writing a program which employs an if-else ladder. It is C’s built-in
multiple branch decision statement. The syntax for the switch statement is as follows:
Should be
included at the Marks the Begin
end of each case and the end of the
statement. switch statement
It causes an exit
from the switch
shunt.
Optional: equivalent to
else used with if
statement
2015-2016
Chap 3. Introduction to programming and 12
C language ©
III.1. 3 switch statement
The switch statement works as follows:
2015-2016
Chap 3. Introduction to programming and 13
C language ©
III.1. 3 switch statement
Important rematks while using a switch
statement:
2015-2016
Chap 3. Introduction to programming and 15
C language ©
III.1. 4 Conclusion
Law of Mosher about software development:
2015-2016
Chap 3. Introduction to programming and 16
C language ©