One Pager Cheat Sheet
- In this lesson we will learn about controlling the flow of execution of programs in Javascript by using
if/else
andtry/catch
statements. If/Else
andTry/Catch
statements are used to control the flow of a program and specify different code execution based on specified conditions and errors/exceptions.- Using If/Else Statements can control the flow of a program and automatically produce the desired output
depending on certain conditions
. - Python's
if
keyword is used to execute a certain task, by evaluating an expression and then executing the statement under the condition that the expression evaluates toTrue
. - We can use
if-elif-else
to create multipleif
statements and add conditions to our code. - It is important to note that an
if
condition must exist for anyelif
orelse
clauses to work. - No limit exists to the number of statements and code blocks (
if
,elif
,else
, etc.) that can be used under anif
block. - The required colon (
:
) is missing from theif
statements andelse
blocks in the code. - Using a
try/catch
statement allows us to handle errors by specifying what to do when an error occurs during the execution of a program. Try/Catch statements in Python
use thetry
andexcept
keywords to allow programs to continue running, even when an exception is raised by thetry
block.- No except block can be called unless a
try
block has been declared and an exception has been raised, as theexcept
block will not be executed without it. - The
try
block will always be executed and will return the value of 1, as theexcept
block cannot be reached without a precedingtry
block. - We learned how to use
if/else
andtry/catch
statements to control program execution and handle any uncertain conditions that may arise when creating complex applications such as those used in artificial intelligence.