Control Flow
If-Else
The if
statement is used to execute a block of code if a condition is true. If the condition is false, the code block will not be executed.
The else
statement is used to execute a block of code if the condition is false
To check multiple conditions, you can use the else if
statement.
Loops
Loops are used to execute a block of code multiple times.
The for
loop is used to execute a block of code a specific number of times.
The while
loop is used to execute a block of code as long as a condition is true.
While Loop
For Loop
The for
loop is used to execute a block of code a specific number of iterations.
It has three parts: initialization, condition, and increment/decrement.