Download as ppsx, pdf, or txt
Download as ppsx, pdf, or txt
You are on page 1of 17

Programming Fundamentals.

Интегрированные среды
разработки программ.

Программаларды құрудың
кіріктірілген орталары.
Demo lesson:
Conditional Statements and Logical
operators
Оператор выбора
Таңдау операторы
YOU WILL:

× identify comparison operators;


× apply if/else statements;
× learn and apply Logical operators (AND,OR, NOT);

× 8.3.3.1 - таңдау және қайталау операторларын программаны өңдеудің


кіріктірілген ортасыныңда қолдану;
× 8.3.3.1 использовать операторы выбора и циклов в интегрированной
среде разработки программ (С/С++, Python, Delphi, Lazarus)

3
Select
таңдау
выбирать

4
to compare
салыстыру -
сравнивать

5
conditional шартты -
условный

6
Indentation
шегініс- отступ

7
value
мән -
значение

8
variable айнымалы -
переменная

9
Discuss the following pictures

10
Conditional statements
People make decisions everyday.
To drink a cup of tea, firstly, we must boil water in a kettle.
Temperature of boiling is 100 Celsius.
Let us understand if water is boiled or not.
We can simply write the following code:
temp = int (input (“What’s temperature of water? ”)
if temp == 100:
print (“It is boiled. Have a nice tea time!”)
In this code we make decisions by using ‘if’ function. So, if temperature of water
becomes equal to 100 degrees Centigrade it will boil and we can have a cup of tea.

11
If / else statement

If / else statement is a decision between two things.


For example, if it is a weekday it is time to go to school. Otherwise, you can
stay home.
We use ‘if’ statement for making only one decision.

What can we do if there are two or more decisions?

12
For example, let us ‘program’ the following situation:
As you know, if temperature outside reaches -30 degrees, school will cancel
the lessons. So let us write a code that will check if it is possible to stay home
or not.
Code:
int temp = int(input(“What’s temperature today?”))
if temp <= -30:
print(“Tadaaa, stay home and have sweet dreams!”)
else:
print(“Hey, get up! You have lessons today!”)

Statements like ‘if’ or ‘if / else’ are called ‘conditional statements’ in


computer programming.

13
Switch

Switch case statements are a substitute for long if statements that compare
a variable to several integral values.
● The switch statement is a multiway branch statement. It provides
an easy way to dispatch execution to different parts of code
based on the value of the expression.
● Switch is a control statement that allows a value to change
control of execution.

14
Flow Diagram

15
Syntax:

16
Important Points about Switch Case Statements:

The expression provided in the switch should result in a constant value otherwise it would not
be valid.
Valid expressions for switch:

17

You might also like