Conditional Statements


If-else statement

If else statement can be used for executing a group statements based on a condition.


If the condition is satisfies then it will be executing if block and if the condition is not satisfied then it will be executing else block.


Rule1: Specifying the condition to if else statement is mandatory and it should be of Boolean type (either a condition or Boolean variable or value).

Rule2: Specifying the else block is optional

Rule3: Specifying the {} is optional . If we don’t specify the {} then it will consider only one statement, and that statement is mandatory. If we want to consider multiple statements then specifying  the else{} is mandatory. Within the {} we can specify any number of statements.

Rule4: In if else statement we cannot execute both the blocks and can not skip the blocks, it will always execute one block.


Leave a Reply