if statement
![](https://codefinity-content-media-v2.s3.eu-west-1.amazonaws.com/courses/a5c23211-8dc2-4c4a-9a83-07a51e843ab6/section_1/TS_meme_9.1%404x.png)
It's our turn to control the code; now we will set conditions for its execution!
Let's consider the most basic form of conditional statements - the if
statement.
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/Java_OOP/Definition_1.png)
If
statement is a fundamental programming construct that allows you to make decisions in your code. It lets you execute a block of code only if a specified condition is true
. If the condition is false
, the code block is skipped, and the program continues with the next instructions. In simpler terms, it's like saying, "If something is true, do this; otherwise, do something else or nothing at all." Let's move on to the syntax:
For example:
That's almost all there is to it, but there's one more thing worth mentioning. Inside the condition
block, there should be a boolean
value. However, we can also place an expression that will result in a boolean
value inside this block, for example:
You can change the value of the variable age
to see how the code works depending on that value.
I'll tell you how to set a condition if the first one doesn't work in the next chapter!
Tudo estava claro?
Conteúdo do Curso
Introduction to TypeScript
Introduction to TypeScript
if statement
![](https://codefinity-content-media-v2.s3.eu-west-1.amazonaws.com/courses/a5c23211-8dc2-4c4a-9a83-07a51e843ab6/section_1/TS_meme_9.1%404x.png)
It's our turn to control the code; now we will set conditions for its execution!
Let's consider the most basic form of conditional statements - the if
statement.
![](https://codefinity-content-media.s3.eu-west-1.amazonaws.com/Java_OOP/Definition_1.png)
If
statement is a fundamental programming construct that allows you to make decisions in your code. It lets you execute a block of code only if a specified condition is true
. If the condition is false
, the code block is skipped, and the program continues with the next instructions. In simpler terms, it's like saying, "If something is true, do this; otherwise, do something else or nothing at all." Let's move on to the syntax:
For example:
That's almost all there is to it, but there's one more thing worth mentioning. Inside the condition
block, there should be a boolean
value. However, we can also place an expression that will result in a boolean
value inside this block, for example:
You can change the value of the variable age
to see how the code works depending on that value.
I'll tell you how to set a condition if the first one doesn't work in the next chapter!
Tudo estava claro?