MySQL Insert with While Loop

drop procedure if exists doWhile; DELIMITER // CREATE PROCEDURE doWhile() BEGIN DECLARE i INT DEFAULT 2376921001; WHILE (i <= 237692200) DO INSERT INTO `mytable` (code, active, total) values (i, 1, 1); SET i = i+1; END WHILE; END; // CALL doWhile();

Assignment Condition in Python While Loop

Starting Python 3.8, and the introduction of assignment expressions (PEP 572) (:= operator), it’s now possible to capture an expression value (here sys.stdin.read(1)) as a variable in order to use it within the body of while: while (i := sys.stdin.read(1)) != ‘\n’: do_smthg(i) This: Assigns sys.stdin.read(1) to a variable i Compares i to \n If … Read more

Perl: while with no conditional

$ perl -MO=Deparse -e ‘while () { }’ while (1) { (); } -e syntax OK It seems that while () {} and while (1) {} are equivalent. Also note that empty parens* are inserted in the empty block. Another example of pre-defined compiler behaviour: $ perl -MO=Deparse -e ‘while (<>) { }’ while (defined($_ … Read more

return in for loop or outside loop

Now someone told me that this is not very good programming because I use the return statement inside a loop and this would cause garbage collection to malfunction. That’s incorrect, and suggests you should treat other advice from that person with a degree of skepticism. The mantra of “only have one return statement” (or more … Read more