top of page
  • Writer's pictureCade.M

Conditional statements

Updated: Sep 6, 2019

The conditional statements used in coding are: if, elif, else. Here I am going to explain what these conditional statements mean and how they work. The 'IF' statement

To put into words, the IF statement works like this:

if "Water" print "The water is streaming down the river" print "Water"

else print "The water is not currently streaming down the river" print "No Water"


IF statement is a function where something could happen happen during that process of the coding. So if something were to happen, that's where the code comes in and prints off from the code.


The 'ELSE' statement

The ELSE statement is a code where if something doesn't happen from the IF code, then something else happens. Think of it as plan B. Because of this, we use ELSE statements to produce more code. If something doesn't go as planned, that's where we use ELSE statements. Here, I will do one example of an ELSE statement if "Brawler punch" print "Brawler punches their opponent"

else

print "Brawler kicks their opponent"


The 'ELIF' statement

The elif statement allows you to check multiple expressions for TRUE and execute a block of code as soon as one of the conditions evaluates to TRUE.

Similar to the else, the elif statement is optional. However, unlike else, for which there can be at most one statement, there can be an arbitrary number of elif statements following an if.


In short, the ELIF statement is like an infinite list of numbers and choices in coding


An example of ELIF would be: print "Hello, [insert name here]!" >>>if name == 'Bob'

print("Hello, Bob!")

elif name == 'Charles'

print("Hello, Charles!") elif name == 'Sucy'

print("Hello, Sucy!")

else

print (Goodbye!)

1 view0 comments

Recent Posts

See All

Comments


bottom of page