View previous topic :: View next topic |
Author |
Message |
LokiChaos
Joined: 27 Oct 2009 Posts: 61
|
Posted: Wed May 04, 2016 1:09 am Post subject: #break and #continue |
|
|
I noticed some odd behaviour with #break and #continue with #forall loops… they do nothing.
#break and #continue do however work with #foreach, #while, #loop, and #parse
Code: |
[02] forall {$t} {#echo {'&0'};#if {&0 > 5} {#break;};#echo {"&0"};}
[02] echo {'1'}
'1'
[10] if {1 > 5}
[05] endif
[02] echo {"1"}
"1"
[02] echo {'2'}
'2'
[10] if {2 > 5}
[05] endif
[02] echo {"2"}
"2"
[02] echo {'3'}
'3'
[10] if {3 > 5}
[05] endif
[02] echo {"3"}
"3"
[02] echo {'4'}
'4'
[10] if {4 > 5}
[05] endif
[02] echo {"4"}
"4"
[02] echo {'5'}
'5'
[10] if {5 > 5}
[05] endif
[02] echo {"5"}
"5"
[02] echo {'6'}
'6'
[10] if {6 > 5}
[00] break
[05] endif
[02] echo {"6"}
"6"
[02] echo {'7'}
'7'
[10] if {7 > 5}
[00] break
[05] endif
[02] echo {"7"}
"7"
[02] echo {'8'}
'8'
[10] if {8 > 5}
[00] break
[05] endif
[02] echo {"8"}
"8"
[02] echo {'9'}
'9'
[10] if {9 > 5}
[00] break
[05] endif
[02] echo {"9"}
"9"
[02] echo {'10'}
'10'
[10] if {10 > 5}
[00] break
[05] endif
[02] echo {"10"}
"10"
[02] forall {$t} {#echo {'&0'};#if {&0 > 5} {#continue;};#echo {"&0"};}
[02] echo {'1'}
'1'
[10] if {1 > 5}
[05] endif
[02] echo {"1"}
"1"
[02] echo {'2'}
'2'
[10] if {2 > 5}
[05] endif
[02] echo {"2"}
"2"
[02] echo {'3'}
'3'
[10] if {3 > 5}
[05] endif
[02] echo {"3"}
"3"
[02] echo {'4'}
'4'
[10] if {4 > 5}
[05] endif
[02] echo {"4"}
"4"
[02] echo {'5'}
'5'
[10] if {5 > 5}
[05] endif
[02] echo {"5"}
"5"
[02] echo {'6'}
'6'
[10] if {6 > 5}
[03] continue
[05] endif
[02] echo {"6"}
"6"
[02] echo {'7'}
'7'
[10] if {7 > 5}
[03] continue
[05] endif
[02] echo {"7"}
"7"
[02] echo {'8'}
'8'
[10] if {8 > 5}
[03] continue
[05] endif
[02] echo {"8"}
"8"
[02] echo {'9'}
'9'
[10] if {9 > 5}
[03] continue
[05] endif
[02] echo {"9"}
"9"
[02] echo {'10'}
'10'
[10] if {10 > 5}
[03] continue
[05] endif
[02] echo {"10"}
"10"
|
I know #forall is somewhat depreciated, so this probably goes mostly unnoticed. |
|
Back to top |
|
 |
LokiChaos
Joined: 27 Oct 2009 Posts: 61
|
Posted: Wed May 04, 2016 1:13 am Post subject: |
|
|
If you want to test:
Code: |
#var t {{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}}
#alias {forall} {
#forall {$t} {
#echo {'&0'};
#if {&0 > 5} {
#break;
};
#echo {"&0"};
};
#forall {$t} {
#echo {'&0'};
#if {&0 > 5} {
#continue;
};
#echo {"&0"};
};
}
#alias {foreach} {
#foreach {$t} {i} {
#echo {'$i'};
#if {$i > 5} {
#break;
};
#echo {"$i"};
};
#foreach {$t} {i} {
#echo {'$i'};
#if {$i > 5} {
#continue;
};
#echo {"$i"};
};
}
#alias {while} {
#var i 0;
#while {$i < 10} {
#math i {$i + 1};
#echo {'$i'};
#if {$i > 5} {
#break;
};
#echo {"$i"};
};
#var i 0;
#while {$i < 10} {
#math i {$i + 1};
#echo {'$i'};
#if {$i > 5} {
#continue;
};
#echo {"$i"};
};
};
#alias {loop} {
#loop {1} {10} {i} {
#echo {'$i'};
#if {$i > 5} {
#break;
};
#echo {"$i"};
};
#loop {1} {10} {i} {
#echo {'$i'};
#if {$i > 5} {
#continue;
};
#echo {"$i"};
};
}
#alias {parse} {
#parse {123456789} {i} {
#echo {'$i'};
#if {$i > 5} {
#break;
};
#echo {"$i"};
};
#parse {123456789} {i} {
#echo {'$i'};
#if {$i > 5} {
#continue;
};
#echo {"$i"};
};
}
|
Each alias should output:
Code: |
'1'
"1"
'2'
"2"
'3'
"3"
'4'
"4"
'5'
"5"
'6'
'1'
"1"
'2'
"2"
'3'
"3"
'4'
"4"
'5'
"5"
'6'
'7'
'8'
'9'
'10'
|
|
|
Back to top |
|
 |
PowerGod
Joined: 04 Aug 2014 Posts: 352
|
Posted: Thu May 05, 2016 10:20 am Post subject: |
|
|
Maybe it's not a case if #forall is not mentioned in the help
Code: |
Command: #break
The break command can be used inside the #FOREACH, #LOOP, #PARSE,
#WHILE and #SWITCH statements. When #BREAK is found, tintin will stop
executing the statement it is currently in and move on to the next.
Example: #while {1} {#math cnt $cnt + 1;#if {$cnt == 20} {#break}}
|
|
|
Back to top |
|
 |
LokiChaos
Joined: 27 Oct 2009 Posts: 61
|
Posted: Thu May 05, 2016 3:15 pm Post subject: |
|
|
Fair enough, just another quirk to #forall then. |
|
Back to top |
|
 |
|