[go: up one dir, main page]

0% found this document useful (0 votes)
6 views1 page

1) Conditional Structures - If... Else

The document discusses conditional structures in programming, specifically the use of 'if...else' statements to execute instructions based on boolean expressions. It provides examples of how to handle different cases, such as solving quadratic equations based on the value of the determinant Delta and displaying the sign of an integer. The syntax for these conditional actions is also outlined, illustrating how to evaluate conditions and execute corresponding actions.

Uploaded by

soufiene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

1) Conditional Structures - If... Else

The document discusses conditional structures in programming, specifically the use of 'if...else' statements to execute instructions based on boolean expressions. It provides examples of how to handle different cases, such as solving quadratic equations based on the value of the determinant Delta and displaying the sign of an integer. The syntax for these conditional actions is also outlined, illustrating how to evaluate conditions and execute corresponding actions.

Uploaded by

soufiene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Algorithmic I Ch 3: Conditional structures – 1) if...

else 2023-2024

Conditional Action :
The conditional action is an instruction that makes it possible to condition the execution of a
sequence of instructions on the value of a boolean expression (condition).
Example :
When solving a quadratic equation, the value of the determinant Delta is calculated, and
depending on the value of the latter there are three actions to consider :
1) Cass Delta˂0 : We display no solution
2) Case Delta=0 : We calculate the value of one
resulat and we display it
3) Case Delta˃0 : We calculate the values of two
results, then we display them

Syntax :

The condition is evaluated. If true, actions 1 of the then clause are executed. Otherwise, actions 2 of the
otherwise clause are executed. In both cases, the algorithm continues after the ‘EndIf’.
Case 2 describes a simplified form of the conditional, without an else clause.

Example 1 : Display the sign of an integer number x.


if (x˃=0) then
Print(ˮx is positiveˮ);
else
Print(ˮx is negativeˮ);
endif;

Example2 : make an integer n even, if it is not so.


if (n mod 2<>0) then
n  n*2 ; /*or :
nn+1 ;*/
endif ;

Page 1 sur 1

You might also like