If statement
Basic If syntax :
if(text expression) {
statement to be executed if it is true;
}
For example:
Try the code. If the statement is true then it will show the result.
If...else Statement
Basic If...else syntax :
If (text expression) {
statements to be executed if expression is true;
}
else {
statements to be executed if expression is false;
}
For example:
Try the code. If the result of num divided by 2 not zero than the num is odd.
If the result of num divided by 2 is zero, then the num is even.
Switch...case Statement
Basic switch...case syntax:
switch(text expression) {
case 1:
code to be executed if text expression equals to case 1;
break;
case 2:
code to be executed if text expression equals to case 2;
break;
.
.
.
.
default:
code to be executed if text expression doesn't equals to any cases;
}
That's the explanation about decision and branch in C programming language. Now, you can try your own code to make decision and branch. Have a great time with coding!
No comments:
Post a Comment