Balanced brackets: Difference between revisions
m
→{{header|D}}
m (→{{header|D}}) |
|||
Line 433:
foreach (int i, char c; s) {
balance += (c == '[' ? 1 : (c == ']' ? -1 : 0));
if (balance < 0) { writeln(` BAD at index %s`, i); continue NEXT_STR; }
}
writeln(` OK!`);// for equal amount of open/closed brackets, balance here is always = 0
Line 441:
Output:
String: ]
String: []
String:
String:
String: []]][[
String: ]][][[
String:
String:
String: [[
▲String: []][][ BAD
=={{header|Euphoria}}==
|