You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@app.celldef_(mo):
ifcondition:
mo.md("Condition is true") # WRONG: Inside if blockelse:
mo.md("Condition is false") # WRONG: Inside else blockreturn
✅ CORRECT Pattern
@app.celldef_(mo):
# Do computation inside control blockstry:
result=some_computation()
message="✅ Success!"exceptExceptionase:
message=f"❌ Error: {e}"# Display OUTSIDE control blocks, BEFORE returnmo.md(message)
return
✅ CORRECT Pattern for Conditionals
@app.celldef_(mo):
# Prepare content based on conditionifcondition:
content="Condition is true"else:
content="Condition is false"# Display OUTSIDE if/else, BEFORE returnmo.md(content)
return
Key Principles
1. Control Blocks vs Display
Control blocks include: try/except, if/else, for loops, while loops, function definitions, with statements
Display functions include: mo.md(), mo.ui.table(), mo.as_html(), etc.
Rule: Display functions must be OUTSIDE control blocks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters