Programming Statements

0.0(0)
studied byStudied by 4 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/16

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

17 Terms

1
New cards

Indentation

Used to declare a block. If the statements are on the same level of indentation, then they are on the same block.

2
New cards

Programming Statements

Running a block of code based on a particular decision.

3
New cards

if statement

Used to test a specific condition, if the condition is true, a block of code (if-block) will be executed.

4
New cards

if-else statement

If the condition in the if statement is false, it will execute the else statement.

5
New cards

elif statement

Checks multiple conditions and executes the block of code of the condition that evaluated to true. Optional like else and can contain multiple elif after an if.

6
New cards

Nested if

Allows the use of another if statements inside an if.

7
New cards

The for loop

Used for iterating on a sequence. A set of statements may be executed once for each item, tuple, set, etc. and does not require an indexing variable to set beforehand.

8
New cards

The break statement (for loop)

Can stop the loop before it has looped through all the items.

9
New cards

The continue statement (for loop)

Can stop the current iteration of the loop, and continue with the next.

10
New cards

The range() function

Returns a sequence of numbers from 0 and increments by 1, by default, and ends at a specified number.

11
New cards

Nested loop

A loop inside a loop. The inner loop will be executed once per iteration of the outer loop.

12
New cards

The pass statement

for loop cannot be empty.

13
New cards

The while loop

As long as the condition is true, it can execute a block of statements. It needs to define an indexing variable.

14
New cards

The break statement (while loop)

The loop can be stopped even if the while condition is still true.

15
New cards

The else statement (while loop)

Can run a block of code when the condition is no longer true.

16
New cards

The do-while loop

Can run at least once. Python does not have a built-in do-while loop but possible to emulate.

17
New cards

Ternary Operator or Conditional Operator

Tests if a condition is true or false and returns the corresponding value, all in one line of code.