BCSC 1102 Introduction to Programming Lecture 3 PPT
BCSC 1102 Introduction to Programming Lecture 3 PPT
The if statement evaluates a condition and executes the code block if the
condition is true.
@*)
1 return 0;
2 }
@*)
1 return 0;
2 }
@*)
The Co-operatetive University of Kenya Sep
Dr. Shem Mbandu Angolo, PhD BCSC 1102 : Intro To Programming Week 3 7 / 18
Nested If Statement (continued)
1 return 0;
2 }
1 case 4:
2 if ( b != 0) {
3 printf ( " Result : ␣ % d \ n " , a / b );
4 } else {
5 printf ( " Division ␣ by ␣ zero ␣ is ␣ not ␣ allowed .\ n " );
6 }
7 break ;
8 default :
9 printf ( " Invalid ␣ operation ␣ selected .\ n " );
10 break ;
11 }
12
13 return 0;
14 }
The for loop is used when the number of iterations is known beforehand.
The while loop is used when the number of iterations is not known
beforehand and depends on a condition.
The do-while loop is similar to the while loop, but it guarantees that
the loop body is executed at least once.
Nested loops are loops within another loop. They are used for
multi-dimensional data structures or complex iterations.
The continue statement skips the current iteration and proceeds to the
next iteration of the loop.