Computer Science, asked by bhandarikshitij4, 3 months ago

Question 1:
a) What do you understand by for loop ? Explain briefly.
Differentiate between if else and switch statement​

Answers

Answered by akshatgupta099
1

Explanation:

a) A loop statement allows us to execute a statement or group of statements multiple times. A for loop is one type of loop where we give the parameters and condition at the beginning based on which the loop executes for the required amount of time. It is an entry controlled loop because the condition is checked at the beginning.

b) An if-else statement can evaluate almost all the types of data such as integer, floating-point, character, pointer, or Boolean. A switch statement can evaluate either an integer or a character or a string. In the case of 'if-else' statement, either the 'if' block or the 'else' block will be executed based on the condition but both the blocks cannot be executed simultaneously. In switch case all the blocks can be executed even if user wants to execute only one block if break statement is not given. If else checks a condition first but the switch case depends solely on the user input.

Answered by Anonymous
0

Answer:

  • loop is a repetitive structure in which a statement or a set of statement is executed a number of times till the given condition becomes false.loop are of two types entry controlled loop and exit controlled loop .in entry controlled loop a condition is checked at the beginning of the loop.this includes for loop and while loop.exit controlled loop is the one in which a condition is checked at the end of the loop.the statement in such a loop gets executed at least once .this include do-while loop.
  • if else is a statement used to check a condition .it is a logical statement in which either of the two statements get executed depending upon the specified condition.when the given condition is true the first set of statement gets executed else the other set of statement gets executed

Syntax:

if(condition)

statement 1;

else

statement 2;

  • switch case statement is a multiple branching statement in which a particular statement is executed out of a number of options as per users choice .in this system the control goes to a specific case and executes the statements for the given switch value.a switch case statement always contains a break statement and default case.teh statement in default case is executed only when the switch value does not match any of the given case. break statement is used a a a case terminator to mark the end of the case. no statement in the switch block is executed after the break statement is encountered .this statement forced the control to exit from switch block

Syntax

switch(n)

{

case 1:

statement;

break;

case 2:

statement;

break;

default:

statement;

}

Similar questions