Cpp.ForStatement Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the for_statement nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.ForStatement represents the node for_statement in the syntax tree of your code.
void example() {
for (int i = 0; i < 10; ++i) {
// loop body
}
}The for (int i = 0; i < 10; ++i) { ... } statement is a
for_statement node that Cpp.ForStatement
models.
Predicates
| Type | Raisable | Printable |
|---|---|---|
ForStatement
| Yes | No |
This class defines these predicates that act on the objects of this class. In addition, objects of this class can access the predicates defined by the base class AstNodeProperties. An object of this class is an object of AstNodeProperties class.
| Predicates | Description | Example |
|---|---|---|
is(required ForStatement &forStatement)
| Matches a for_statement node and binds it to
forStatement for further queries. | This PQL defect checks for any defect FindFor =
when
Cpp.ForStatement.is(&forStmt)
and forStmt.nodeText(&txt)
raise "Found for: \"{txt}\""
on forStmtIn this C++ code, the defect finds the top-level
int main() {
for (int i = 0; i < 3; ++i) { }
return 0;
} |
cast(Cpp.Node.Node node, required ForStatement &cast)
| Checks whether a Cpp.Node.node is a
for_statement and if so binds it as cast for
using ForStatement predicates. | This PQL defect checks for a defect CastToFor =
when
Cpp.Node.is(&node,&,&,&)
and Cpp.ForStatement.cast(node, &forStmt)
and forStmt.nodeText(&txt)
raise "Casted node is for: \"{txt}\""
on forStmtIn this C++ code, the defect looks for a
void f() {
for (int i = 0; i < 1; ++i) {}
} |
isa(Cpp.Node.Node node)
| Checks whether a Cpp.Node.node is a
for_statement returning true or allowing negation. | This PQL defect checks whether a converted node is a
defect NotAFor =
when
Cpp.Node.is(&node,&,&,&)
and not Cpp.ForStatement.isa(node)
raise "Node is not a for_statement"
on exprStmtIn this C++ code, the defect finds syntax nodes
that are not a
void g() {
int x = 0;
} |
initializer(ForStatement self, Cpp.Node.Node &child)
| Returns the initializer part of a for loop such as a
declaration or expression as child. | This PQL defect checks for a defect ForHasInit =
when
Cpp.ForStatement.is(&forStmt)
and forStmt.initializer(&init)
and init.nodeText(&txt)
raise "For initializer: \"{txt}\""
on forStmtIn this C++ code, the defect finds the
void h() {
for (int i = 0; i < 2; ++i) { }
} |
condition(ForStatement self, Cpp.Node.Node &child)
| Returns the loop condition expression of a for loop as
child. | This PQL defect checks for a defect ForHasCond =
when
Cpp.ForStatement.is(&forStmt)
and forStmt.condition(&cond)
and cond.nodeText(&txt)
raise "For condition: \"{txt}\""
on forStmtIn this C++ code, the defect finds the
void k() {
for (int i = 0; i < 10; ++i) { }
} |
update(ForStatement self, Cpp.Node.Node &child)
| Returns the update expression of a for loop such as
++i or i++ as
child. | This PQL defect checks for the update expression of a
defect ForHasUpdate =
when
Cpp.ForStatement.is(&forStmt)
and forStmt.update(&upd)
and upd.nodeText(&txt)
raise "For update: \"{txt}\""
on forStmtIn this C++ code, the defect captures the
void m() {
for (int i = 0; i < 5; ++i) { }
} |
body(ForStatement self, Cpp.Node.Node &child)
| Returns the loop body of the for_statement which may be a
compound statement or a single statement as child. | This PQL defect checks for the body of a defect ForHasBody =
when
Cpp.ForStatement.is(&forStmt)
and forStmt.body(&body)
and body.nodeText(&txt)
raise "For body: \"{txt}\""
on forStmtIn this C++ code, the defect finds the
void n() {
for (int i = 0; i < 2; ++i) {
int x = i;
}
} |
getEnclosingForStatement(Cpp.Node.Node child, required ForStatement
&parent)
| Finds the nearest enclosing for_statement ancestor of the
given child node and returns it as
parent. | This PQL defect checks for the closest enclosing
defect EnclosingFor =
when
Cpp.ReturnStatement.is(&ret)
and ret.toNode(&node)
and Cpp.ForStatement.getEnclosingForStatement(node, &forParent)
and forParent.nodeText(&txt)
raise "Enclosing for: \"{txt}\""
on forParentIn this C++ code, the defect finds the nearest
int foo() {
for (int i = 0; i < 3; ++i) {
if (i == 1) return 42;
}
return 0;
} |
isEnclosedInForStatement(Cpp.Node.Node child)
| Checks whether the given child node has a
for_statement as an ancestor and returns true if so. | This PQL defect checks whether a node is inside any
defect InsideFor =
when
Cpp.BreakStatement.is(&brk)
and brk.toNode(&node)
and Cpp.ForStatement.isEnclosedInForStatement(node)
raise "Break is inside a for"
on brkIn this C++ code, the defect identifies a
void p() {
for (;;) {
break;
}
} |
Version History
Introduced in R2026a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)