Awkward control structure

RAMontante bobmon at iuvax.cs.indiana.edu
Sat Feb 25 06:43:59 AEST 1989


davidsen at crdos1.UUCP (bill davidsen) <13233 at steinmetz.ge.com> :
-	[ ... ]
-
-  Or, more simply with a goto:
-      UglyLabel:
-	if (!valid_pwd) {
-	  ask for password
-	  goto UglyLabel;
-	}
-	else {
-	  validate password
-	}
-
-  The object of this is not to ask the user to type a new password once
-to set it, once to confirm you have it right, and then once again to
-validate it. Twice is enough, particularly over a noisy phone line!


(I'm not convinced that this goto example won't ask the new-user to
validate the password once it's correctly entered.  In any case...)

Why do you want to avoid doubling the valid_pwd test?  The code size
shouldn't be a big factor, and the number of executions stays the
same.  I would think a natural control flow would be

	if (valid_pwd()) {
		validate_password();
	} else
		do {
			get_new_password();
		} while (!valid_pwd());

[I've made some things real C functions just for consistency with the
control-structure syntax.]



More information about the Comp.lang.c mailing list