0Pricing
Mojo Academy · Lektion

Mit if/else Entscheidungen treffen

Verzweigen Sie anhand von Bedingungen.

Mit if/else Entscheidungen treffen ist eine kostenlose Mojo Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Mojo Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Code That Decides

Programs often need to choose a path. The if statement runs a block only when its condition is true, so your code can react to data. 🔀

Your First if

Write if, a condition, a colon, then an indented block. If the condition holds, Mojo runs the block; otherwise it skips it entirely.

if score > 90:
    print("Top marks!")

Conditions Are Booleans

The bit after if must boil down to True or False. Comparisons like greater-than and equals naturally produce a boolean for you.

var ready = count == 0
if ready:
    print("Empty")

Add an else Branch

Pair else with if to cover the other case. Exactly one of the two blocks runs, so nothing is ever left unhandled.

if temp > 30:
    print("Hot")
else:
    print("Mild")

Indentation Defines the Block

Like Python, Mojo uses indentation to mark what belongs to a branch. Consistent spaces, usually four, keep the structure clear and valid.

Comparison Operators

Build conditions with operators like ==, !=, <, and >=. Each compares two values and hands back the boolean that if needs.

if age >= 18:
    print("Adult")

Chain More Cases with elif

Need more than two paths? Insert one or more elif branches between if and else to test extra conditions in order.

if g >= 90:
    print("A")
elif g >= 80:
    print("B")
else:
    print("C")

Only the First Match Wins

Mojo checks branches top to bottom and stops at the first condition that is true. The rest are skipped, even if they would also match.

Combine Conditions with and / or

Join checks using and and or. With and both must be true; with or just one is enough to enter the block.

if hungry and has_food:
    print("Eat now")

Flip a Condition with not

Put not in front of a condition to invert it. It turns True into False, handy for checking the absence of something.

if not logged_in:
    print("Please sign in")

Nesting Branches

You can place an if inside another branch to refine a decision. Keep nesting shallow so the logic stays easy to read.

if signed_in:
    if is_admin:
        print("Dashboard")

Quick Check

You want to handle three or more separate cases in one decision. Which keyword do you reach for?

Recap

You branch with if, add else for the other case, and chain elif for more. Conditions are booleans you can combine with and, or, and not. 🎯

Häufig gestellte Fragen

Ist die Lektion „Mit if/else Entscheidungen treffen“ kostenlos?

Ja — der vollständige Text von „Mit if/else Entscheidungen treffen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Mojo Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Mit if/else Entscheidungen treffen“?

Verzweigen Sie anhand von Bedingungen. Du übst Mojo Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Mojo Academy zu starten?

Keine Vorkenntnisse erforderlich. Mojo Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „Mit if/else Entscheidungen treffen“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Mojo Academy-Lektion Code schreiben und ausführen?

Ja. Jede Mojo Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Mit if/else Entscheidungen treffen
  2. Schleifen mit while
  3. Mit for und range iterieren
  4. break, continue und vorzeitiger Abbruch
← Zurück zu Mojo Academy