The code can be replaced by a one-liner:
B = isequal(sort(fieldnames(a)), sort(fieldnames(b)))
I do like the fact that you have written a clear help section, including a H1 line. As for your code, as soon as B becomes false in the for-loop you can issue a return command (no need to check the remaining field names).
You also might want to check if the input are indeed structures.