Repository navigation
While Wend or While End While
Home › Control Flow Statements › While...Wend (Or 'While...End While')
Control flow statement for looping
While [condition]
[statement block]
Wend '' or End WhileThe While statement will cause the following set of statements in the statement block to execute repeatedly if and while the expression condition evaluates to true.
If condition evaluates to false when the While statement is first executed, then the statement block is skipped and execution resumes immediately following the enclosing Wend statement.
If an Exit While statement is encountered inside the statement block, the loop is terminated, and execution resumes immediately following the enclosing Wend statement. If a Continue While statement is encountered, the rest of the statement block is skipped and execution resumes at the While statement.
Like all control flow statements, the While statement can be nested, that is, it can be used in a statement block of another While statement.
note: the Whilekeywordis also used in the Do...Loop statement to indicate the type of comparison. Used in this way, the Do statement becomes functionally equivalent to the While statement, so do not confuse their enclosing keywords Loop and Wend, respectively.
- In the -lang qb and -lang fblite dialects, variables declared inside a
While..Wendloop have a function-wide scope as in QB In the -lang fb and -lang deprecated dialects, variables declared inside aWhile..Wendblock are visible only inside the block, and can't be accessed outside it. To access duplicated symbols defined as global outside this block, add one or preferably two dot(s) as prefix:.SomeSymbolor preferably..SomeSymbol(or only..SomeSymbolif inside a With..End With block).
- None, except for the
End Whilesyntax (equivalent toWend) specific to FreeBASIC.
In this example, a While loop is used to reverse a string by iterating through it backward. The loop stops if index is less than 0 (0 being the first index in the string).
Dim As String sentence '' string to reverse
sentence = "The quick brown fox jumps over the lazy dog."
Dim As String ecnetnes
Dim As Integer index
index = Len( sentence ) - 1 '' point to last character
While( index >= 0 ) '' stop after first character
ecnetnes += Chr( sentence[index] ) '' append character to new string
index -= 1
Wend
Print "original: """ ; sentence ; """"
Print "reversed: """ ; ecnetnes ; """"
End 0Category: Control Flow Statements
Kind: keyword
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing