Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Say you want to validate a few things before you
- // run the database query. Here I've used only 3 checks,
- // but go figure with 20+ checks! You'll need a HUGE
- // widescreen monitor to make it all fit.
- if(hasEnoughMoney()) {
- if(hasEnoughIQ()) {
- if(someOtherCheck()) {
- mysql_query("wooot!");
- print "Your order has been placed.";
- } else {
- print "not enough cash";
- }
- } else {
- print "You are too dumb";
- }
- } else {
- print "not enough cash";
- }
- ---------------------------
- // Using this could be a much cleaner solution:
- // the do... while is just there so we can "break"
- // the code. You can use a GOTO too, but people seem
- // to hate that. (oh, you can use a switch(), too).
- do {
- if(!hasEnoughMoney()) {
- print "not enough cash";
- break;
- }
- if(!hasEnoughIQ()) {
- print "You are too dumb";
- break;
- }
- if(!someOtherCheck()) {
- print "some check failed.";
- break;
- }
- // All checks passed! Run critical code.
- mysql_query("wooot!");
- print "Your order has been placed.";
- } while(false);
Advertisement
Add Comment
Please, Sign In to add comment