| Line 1... |
Line 1... |
| 1 |
% File src/library/base/man/Control.Rd
|
1 |
% File src/library/base/man/Control.Rd
|
| 2 |
% Part of the R package, https://www.R-project.org
|
2 |
% Part of the R package, https://www.R-project.org
|
| 3 |
% Copyright 1995-2024 R Core Team
|
3 |
% Copyright 1995-2025 R Core Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{Control}
|
6 |
\name{Control}
|
| 7 |
\title{Control Flow}
|
7 |
\title{Control Flow}
|
| 8 |
\alias{Control}
|
8 |
\alias{Control}
|
| Line 67... |
Line 67... |
| 67 |
the loop; changing it subsequently does not affect the loop. If
|
67 |
the loop; changing it subsequently does not affect the loop. If
|
| 68 |
\code{seq} has length zero the body of the loop is skipped. Otherwise the
|
68 |
\code{seq} has length zero the body of the loop is skipped. Otherwise the
|
| 69 |
variable \code{var} is assigned in turn the value of each element of
|
69 |
variable \code{var} is assigned in turn the value of each element of
|
| 70 |
\code{seq}. You can assign to \code{var} within the body of the loop,
|
70 |
\code{seq}. You can assign to \code{var} within the body of the loop,
|
| 71 |
but this will not affect the next iteration. When the loop terminates,
|
71 |
but this will not affect the next iteration. When the loop terminates,
|
| 72 |
\code{var} remains as a variable containing its latest value.
|
72 |
\code{var} remains as a variable containing its latest value. The
|
| - |
|
73 |
\code{seq} is implicitly unclassed. For classed objects, one can use
|
| - |
|
74 |
\code{\link{as.list}} to prepare a list to iterate over or
|
| - |
|
75 |
\code{\link{seq_along}} to get an index vector and then explicitly extract
|
| - |
|
76 |
individual elements (see also \code{\link{lapply}}).
|
| 73 |
|
77 |
|
| 74 |
The null coalescing operator \code{\%||\%} is a simple 1-line function:
|
78 |
The null coalescing operator \code{\%||\%} is a simple 1-line function:
|
| 75 |
\code{x \%||\% y} is an idiomatic way to call
|
79 |
\code{x \%||\% y} is an idiomatic way to call
|
| 76 |
\preformatted{
|
80 |
\preformatted{
|
| 77 |
if (is.null(x)) y else x
|
81 |
if (is.null(x)) y else x
|