answersLogoWhite

0

// Why do you need if/else statements?

int main()

{

int numbers[] = {1, 2, 3, 4, 5, 6}; // and so on

int i;

int sum = 0;

for(i = 0; i < sizeof (numbers)/sizeof(int); i++)

sum += i;

return sum;

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Continue Learning about Engineering

What are sequential if then else patterns?

A sequential if-then-else pattern is a pattern where the program checks on thing at a time using if statements. For example, in C: if (condition 1) { do something 1; } else if (condition 2) { do something 2; } else if (condition 3) { do something 3; } else { do something else; } The first condition that is true will be executed.


What are the various control statement in C language?

Control statements are the statements that control the flow of program execution. For eg: loops: For, While, Do-While, decision making using if-then-else or switch-case and there's goto to transfer control.


Program for electricity bill using if-else ladder in c?

if (has_enough_money) { pay_the_bill(); }


Four basic instruction in C language?

They are 'statements' to speak strictly, they are: , , if, else, while, for, do, return, switch, break, continue, gotoNote: is zero or more statements between '{' and '}'


Structure of If-Then statement?

if (condition) statement1 [else statement2] example: if (i==j); else if (j==k) printf ("i!=j, j==k\n); else printf ("i!=j, j!=k\n); here statement1 is an empty-statement, statement2 is another if-statement There are three forms of statements IF-THEN IF-THEN-ELSE IF-THEN-ELSIF Sequence of statements is executed only if the condition evaluates to TRUE If condition evaluates to FALSE or NULL, it does nothing In either case control passes to next statement after the IF-THEN structure IF THEN statements; END IF; Sequence of statements in the ELSE clause is executed only if the condition evaluates to FALSE or NULL IF THEN statements; ELSE statements; END IF;

Related Questions

Write a program By using if else statement to read a number and check whether it is positive or negative?

write a c++program by using if statement to read a number and check whether it is positive or negative


What are sequential if then else patterns?

A sequential if-then-else pattern is a pattern where the program checks on thing at a time using if statements. For example, in C: if (condition 1) { do something 1; } else if (condition 2) { do something 2; } else if (condition 3) { do something 3; } else { do something else; } The first condition that is true will be executed.


What are the various control statement in C language?

Control statements are the statements that control the flow of program execution. For eg: loops: For, While, Do-While, decision making using if-then-else or switch-case and there's goto to transfer control.


How do you group multiple PHP statements under an if statement?

If I got your question correctly, you want multiple statements to be executed using if-else statement. Here goes the code for it if($x&gt;0) { // multiple statments here // As long as statements are in curly bracket // All of them would execute // before the if statement finishes } else { // same way put all your multiple statements // in curly brackets. All of them would execute // using a single if-else statement }


Is it possible to use multiple else statements with if statements?

yes


Program for electricity bill using if-else ladder in c?

if (has_enough_money) { pay_the_bill(); }


You want to write program comparing 1 is greater than less than or equal to 100?

This requires a number of conditional statements, with IF. The details vary from one language to another; the result should be similar to this: x = 1 y = 100 if x &lt; y Output "The first number is greater" else if x &gt; y Output "The second number is greater" else Output "Both numbers are equal" end if Individual commands and statements must be adapted to the specific language, for example, the "Output" statement.


Four basic instruction in C language?

They are 'statements' to speak strictly, they are: , , if, else, while, for, do, return, switch, break, continue, gotoNote: is zero or more statements between '{' and '}'


Structure of If-Then statement?

if (condition) statement1 [else statement2] example: if (i==j); else if (j==k) printf ("i!=j, j==k\n); else printf ("i!=j, j!=k\n); here statement1 is an empty-statement, statement2 is another if-statement There are three forms of statements IF-THEN IF-THEN-ELSE IF-THEN-ELSIF Sequence of statements is executed only if the condition evaluates to TRUE If condition evaluates to FALSE or NULL, it does nothing In either case control passes to next statement after the IF-THEN structure IF THEN statements; END IF; Sequence of statements in the ELSE clause is executed only if the condition evaluates to FALSE or NULL IF THEN statements; ELSE statements; END IF;


What is the similarity between 'if' statement ans 'switch' statement?

A Switch statement can be considered as a series of if. else if. else statements. whatever condition is satisfied, the code block would get executed. if (cond 1) { } else if (cond 2) { } else if (cond 3) { } ...... } else if (cond N) { } else { } switch { case 1: .... case 2: .... .... case N: ... default: ... } Difference: In the if else blocks, if one condition is satisfied, all other blocks are ignored In Switch blocks, unless you have break statements inside each condition block, the subsequent blocks would not be ignored.


How can a switch loop be used to efficiently iterate through different cases in a program?

A switch loop can efficiently iterate through different cases in a program by evaluating a variable or expression and then executing the corresponding case without having to check each case individually. This can make the code more organized and easier to read compared to using multiple if-else statements.


Java script program using if else?

Here we go... if(document.addListener){ alert("Yay! Not IE!"); }else{ alert("Booo! IE or something terribly old."); }