Cover photo

Conditionals

In programming it's often necessary to write code that depends on some condition to be true.

プログラミングでは、ある条件が真であることが必要な場合にコードを書くことがよくあります。

.

For a good example, let's imagine we're building a website!

良い例として、ウェブサイトを構築しているとしましょう!

.

We want users to be sent to the dashboard only if they are logged in. Otherwise we should send them to the login page:

ユーザーがログインしている場合にのみダッシュボードに転送し、そうでなければログインページに転送する必要があります:

.

if(loggedIn) {
    // loggedIn is true
    goToDashboard();
}
else {
    // loggedIn is false
    goToLogin();
}

.

You could think of this logic as: If the user is logged in, then send them to the dashboard. If not, send them to the login page.

このロジックは、ユーザーがログインしている場合はダッシュボードに送信し、そうでなければログインページに送信すると考えることができます。

.

Our logic is branched based on the condition of whether or not the user is logged in. We can look at this from the perspective of a flow chart:

私たちのロジックは、ユーザーがログインしているかどうかの条件に基づいて分岐されます。これをフローチャートの観点から見ることができます:

.

post image

.

Ready to start coding your own conditionals? Let's get into it!

独自の条件を書き始める準備はできましたか?さあ始めましょう!

.

.

.

NEXT ⇒⇒