0% found this document useful (0 votes)
64 views3 pages

Reading in English Week 3 Day 11 Theme: The Importance of Conditionals in Programming

Conditional statements are essential in programming to alter program flow based on different conditions. The most common conditional statements are IF-THEN, IF-THEN-ELSE, and SWITCH/CASE statements. Conditional logic allows programs to handle multiple possible cases and run different algorithms based on the conditions. For example, a method for selling products would need conditional logic to handle selling quantities that are above or below inventory levels. Logical operators like ==, >, <, !=, &&, and || are used to combine logical expressions into conditions.

Uploaded by

Juliana Martinez
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)
64 views3 pages

Reading in English Week 3 Day 11 Theme: The Importance of Conditionals in Programming

Conditional statements are essential in programming to alter program flow based on different conditions. The most common conditional statements are IF-THEN, IF-THEN-ELSE, and SWITCH/CASE statements. Conditional logic allows programs to handle multiple possible cases and run different algorithms based on the conditions. For example, a method for selling products would need conditional logic to handle selling quantities that are above or below inventory levels. Logical operators like ==, >, <, !=, &&, and || are used to combine logical expressions into conditions.

Uploaded by

Juliana Martinez
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/ 3

Reading in English Week 3 Day 11

Theme: The importance of conditionals in programming

In programming, a conditional statement is an instruction or group of instructions that can


be executed or not depending on the value of a condition.

The most known types of conditional statements are the IF..THEN, the IF..THEN..ELSE and
the CASE or SWITCH, although we could also mention the handling of exceptions as a more
modern alternative to avoid the "nesting" of conditional statements.

Conditional statements are, together with loops, the pillars of structured programming, and
their use is an evolution of assembly language statements.

A conditional instruction allows us to pose the solution to a problem considering the different
cases that may arise. In this way, we can use a different algorithm to face each case that
may exist in the world.

Consider the method of the Product class which is responsible for selling a certain number
of units present in the winery. There, two possible cases can be presented, eac h with a
different solution: the first case is when the quantity you want to sell is greater than the
quantity available in the warehouse (the order is greater than the availability) and the
second is when there are enough units of the product in the warehouse to make the sale.
In each of these situations the solution is different and the method must have a different
algorithm.

As explained above, there are two ways to alter the flow depending on a condition. The basic
idea is to find ourselves at a fork in the road, where we will follow one or the other depending
on the answer to a question written at the fork. A variant of this is that instead of two
possibilities, we are presented with more paths to follow.

“Formando líderes para la construcción de un nuevo país en paz”


Universidad de Pamplona
Pamplona - Norte de Santander - Colombia 1
Tels: (7) 5685303 - 5685304 - 5685305 - Fax: 5682750
SC-CER96940 www.unipamplona.edu.co
Logical operators

Logical operators allow you to group logical expressions. Logical expressions are all
those expressions that obtain as a result true or false. Logical operators are those
that link this type of expressions. To create conditions, no matter how simple they
are, you need logical operators.

Among which it is possible to mention:

== means "equal". If x==y, it means "if x is equal to y".

> means "greater than". If x>y, it means "if x is greater than y".

< means "less than". If x<y, it means "if x is less than y".

! = means "if different". If x!=y, means "if x is different from y".

&& means "Y", the copulative conjunction; that is: If (x==y) && (x==z), means "if x is
equal to y Y x is equal to z.

|| means "O", the adverse conjunction; that is, If (x==y) || (x==z), means "if x is equal
to y O x equals z".

Operator and: The operator and evaluates if the value of the left side and the right side is
met.

>>> True and False

False

“Formando líderes para la construcción de un nuevo país en paz”


Universidad de Pamplona
Pamplona - Norte de Santander - Colombia 2
Tels: (7) 5685303 - 5685304 - 5685305 - Fax: 5682750
SC-CER96940 www.unipamplona.edu.co
Operator or: The operator or evaluates whether the value on the left side or the right side
is met.

>>> True or False

True

Operator not: The operator not returns the opposite value to the boolean value.

>>> not True

False

If the expression is True the returned value is False, otherwise if the expression is False the
returned value is True.

>>> not False

True

References:

 Megacursos.com
 Universidad de los Andes, fundamentos de programación
 Codenotch coding school S.L

“Formando líderes para la construcción de un nuevo país en paz”


Universidad de Pamplona
Pamplona - Norte de Santander - Colombia 3
Tels: (7) 5685303 - 5685304 - 5685305 - Fax: 5682750
SC-CER96940 www.unipamplona.edu.co

You might also like