0
Can any one explian me this in simple language
conditional looping and conditional statements
2 Answers
0
if trafficLight == 'red':
wait
else:
walk
0
Conditional statement:
if ([some expression that can be false or true]) {
[some code that will be executed only if the expression above is TRUE]
} else {
[some code that will be executed only if the expression above is FALSE]
}
example in C:
int k;
scanf("%d", &k); // enter the number
if (k >= 5)
printf("%d >= five", k); // this code will be executed if number >= 5
} else {
printf("%d < five", k); // this code will be executed if number < 5
}
Conditional loop:
while ([some expression that can be false or true]) {
[which will run again and again while the expression above is TRUE]
}
example in C:
int num = 1;
while (num <= 10) {
printf("%d, ", num);
num = num + 1;
}
Output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,