.\" Man page generated from reStructuredText
.\" by the Docutils 0.22.4 manpage writer.
.
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "WHILE" "1" "Mar 28, 2026" "4.6" "fish-shell"
.SH NAME
while \- perform a set of commands multiple times
.SH SYNOPSIS
.nf
\fBwhile\fP \fICONDITION\fP\fB;\fP \fICOMMANDS\fP\fB;\fP \fBend\fP
.fi
.sp
.SH DESCRIPTION
.sp
\fBwhile\fP repeatedly executes \fBCONDITION\fP, and if the exit status is 0, then executes \fBCOMMANDS\fP\&.
.sp
The exit status of the \fBwhile\fP loop is the exit status of the last iteration of the \fBCOMMANDS\fP executed, or 0 if none were executed. (This matches other shells and is POSIX\-compatible.)
.sp
You can use and \%<> or or \%<> for complex conditions. Even more complex control can be achieved with \fBwhile true\fP containing a break \%<>\&.
.sp
The \fB\-h\fP or \fB\-\-help\fP option displays help about using this command.
.SH EXAMPLE
.INDENT 0.0
.INDENT 3.5
.sp
.EX
while test \-f foo.txt; or test \-f bar.txt ; echo file exists; sleep 10; end
# outputs \(aqfile exists\(aq at 10 second intervals,
# as long as the file foo.txt or bar.txt exists.
.EE
.UNINDENT
.UNINDENT
.SH Copyright
fish-shell developers
.\" End of generated man page.
