Control statement is used to take a decision or choose the programs to be undertaken in accordance with the conditions or terms provided. OR Branching is a selection of statements to be executed when the selection was based on certain conditions.
The statement above-statement needs a condition or conditions as the basis for decision making. One of the commonly used condition is a state of true or false (true or false). C language provides several statements control, such as:
If statement If-else statement, and Switch statement
IF Structure of the conditions.
This structure is the simplest structure because it only involves one expression to be examined. If the condition is false, will do nothing in the instruction IF (straight to the next instruction). The structure is as follows:
/ / If only one statement made
if (condition) statement
/ / If more than one statement
if (condition) {
statemen1;
statemen2;
... .. }
The structure of the two conditions
Branching structure of this type a little more complex when compared with the structures that have only one condition. The structure is as follows:
if (condition)
{Statemen_jika_kondisi_terpenuhi;} else
{Statemen_jika_kondisi_tidak_terpenuhi;}
The structure of the three conditions
Branching of this type is an extension of the branching structure with one and two conditions. The structure is as follows:
if (kondisi_1)
{Statemen_jika_kondisi_1_terpenuhi;} else if (kondisi_2)
{Statemen_jika_kondisi_2_terpenuhi;} else if (kondisi_3)
{Statemen_jika_kondisi_3_terpenuhi;} else
{Statemen_jika_semua_kondisi_diatas_tdk_terpenuhi;}
The statement above-statement needs a condition or conditions as the basis for decision making. One of the commonly used condition is a state of true or false (true or false). C language provides several statements control, such as:
If statement If-else statement, and Switch statement
IF Structure of the conditions.
This structure is the simplest structure because it only involves one expression to be examined. If the condition is false, will do nothing in the instruction IF (straight to the next instruction). The structure is as follows:
/ / If only one statement made
if (condition) statement
/ / If more than one statement
if (condition) {
statemen1;
statemen2;
... .. }
The structure of the two conditions
Branching structure of this type a little more complex when compared with the structures that have only one condition. The structure is as follows:
if (condition)
{Statemen_jika_kondisi_terpenuhi;} else
{Statemen_jika_kondisi_tidak_terpenuhi;}
The structure of the three conditions
Branching of this type is an extension of the branching structure with one and two conditions. The structure is as follows:
if (kondisi_1)
{Statemen_jika_kondisi_1_terpenuhi;} else if (kondisi_2)
{Statemen_jika_kondisi_2_terpenuhi;} else if (kondisi_3)
{Statemen_jika_kondisi_3_terpenuhi;} else
{Statemen_jika_semua_kondisi_diatas_tdk_terpenuhi;}
No comments:
Post a Comment