10.5.1 Перебор элементов структуры
Специальная форма оператора for позволяет перебрать все элементы структуры:
for [ val, key ] = expression body endfor
В этой форме оператора for значение expression должно быть структурой. Если это так, key и val поочерёдно принимают имя элемента и соответствующее значение, пока не будут перебраны все элементы. Например:
x.a = 1
x.b = [1, 2; 3, 4]
x.c = "string"
for [val, key] = x
key
val
endfor
-| key = a
-| val = 1
-| key = b
-| val =
-|
-| 1 2
-| 3 4
-|
-| key = c
-| val = string Элементы не перебираются в каком-либо определённом порядке. Если вам нужно перебрать список в определённом порядке, воспользуйтесь функцией fieldnames и отсортируйте список самостоятельно.
© 1996–2026 The Octave Project Developers
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://docs.octave.org/v9.4.0/Looping-Over-Structure-Elements.html