๐ Special Loops
Special loops to simplify common iterative processes.
warning
Special loops cannot be nested. Starting a new special loop inside another will cause unexpected results.
loopโ
Performs iterations based on numerical sequences.
Argument | Description |
---|---|
N1 | Start integer (if alone, iterates 1 to N1) |
N2 | End integer (optional, iterates N1 to N2) |
note
The $INDEX
variable reflects the current iteration number.
# From 1 to 100
loop 100; do
ui_print "Iteration: $INDEX"
done
# From 5 to 10
loop 5 10; do
ui_print "At: $INDEX"
done
loop_fileโ
Iterates over each line in a file.
Argument | Description |
---|---|
FILE | File to read |
note
$INDEX
: Current line number.$LINE
: Content of the current line.
loop_file "/sdcard/file.txt"; do
ui_print "LINE NUMBER: $INDEX"
ui_print "LINE CONTENT: $LINE"
done
loop_stringโ
Breaks text into segments based on delimiters and iterates over them.
Argument | Description |
---|---|
DELIMITERS | Characters to split on (empty "" splits by char) |
TEXT | Text to split |
note
$INDEX
: Current segment number.$SECTION
: Content of the current segment.
# Single delimiter
loop_string ";" "First; Second; Third"; do
ui_print "SEGMENT NUMBER: $INDEX"
ui_print "SEGMENT CONTENT: $SECTION"
done
# Multiple delimiters
loop_string ";$:" "First; Second$ Third: Four"; do
ui_print "SEGMENT NUMBER: $INDEX"
ui_print "SEGMENT CONTENT: $SECTION"
done
# Character by character
loop_string "" "Hello"; do
ui_print "CHAR NUMBER: $INDEX"
ui_print "CHAR: $SECTION"
done
loop_arrayโ
Iterates over elements in an array.
Argument | Description |
---|---|
ARRAY NAME | Name of the array |
note
$KEY
: Access key of the current element.$VALUE
: Value of the current element.
declare -A SOMETHING=(
["key1"]="value1"
["key2"]="value2"
["key3"]="value3"
)
loop_array SOMETHING; do
ui_print "KEY: $KEY"
ui_print "VALUE: $VALUE"
done