If class¶
This page explains the If
class.
Before reading on, maybe it is helpful to read the following page (the apysc uses the If
class for the same reason of each apysc data type):
What is the If class?¶
The If
class is the apysc branch instruction class. It behaves like the Python built-in if
keyword.
Basic usage¶
The If
class requires the with
statement as follows:
import apysc as ap
ap.Stage()
condition: ap.Boolean = ap.Boolean(True)
with ap.If(condition):
...
The If
class requires passing the Boolean
value as the condition.
See also¶
If constructor API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface signature] __init__(self, condition: Union[apysc._type.boolean.Boolean, NoneType], *, locals_: Union[Dict[str, Any], NoneType] = None, globals_: Union[Dict[str, Any], NoneType] = None) -> None
[Interface summary]
A class to append if branch instruction expression.
[Parameters]
condition
: Boolean or NoneBoolean value to be used for judgment.
locals_
: dict or None, default NoneCurrent scope’s local variables. Set locals() value to this argument. If specified, this interface reverts all local scope VariableNameMixIn variables (like Int, Sprite) at the end of an
If
scope. This setting is useful when you don’t want to update each variable by implementing theIf
scope.
globals_
: dict or None, default NoneCurrent scope’s global variables. Set globals() value to this argument. This setting works the same way as the locals_ argument.
[Examples]
>>> import apysc as ap
>>> int_val: ap.Int = ap.Int(10)
>>> condition: ap.Boolean = int_val >= 10
>>> with ap.If(condition):
... ap.trace("Int value is greater than equal 10!")
...
[References]