C7.5: Control Structures Flashcards
1
Q
What are the two types of control structures?
A
Selection and loops.
2
Q
What are the different types of selection?
A
if statement, switch statement, conditional operator
3
Q
What are the three kinds of loops?
A
while loop, do while loop and for loop.
4
Q
Give an example of a switch statement.
A
int x = 2; switch (x) { case 1: printf("Choice is 1"); break; case 2: printf("Choice is 2"); break; case 3: printf("Choice is 3"); break; default: printf("Choice other than 1, 2 and 3"); break; }
5
Q
Give an example of a do while loop.
A
do{
printf(ā%d \nā,i);
i++;
}while(i<=10);