In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces what is the difference between While, Loop and Repeat loop sentences. It is very detailed and has a certain reference value. Interested friends must read it!
Similarities: can not be used alone, mainly used in stored procedures and functions FUNCTION. Difference: WHILE judges first, then executes, and executes only when the conditions are met. REPEAT and LOOP execute first and then judge; the loop ends when the condition is met. When the condition is false, REPEAT can also be executed once; the other two statements cannot be executed.
I. Overview of MySQL cycle
There are three kinds of loops in MySQL, namely WHILE, REPEAT, LOOP (and supposedly goto), which cannot be used alone and are mainly used in stored procedure PROCEDURE and function FUNCTION.
2. WHILE cycle
1. Syntax: WHILE condition DO doSomething END WHILE
2. Note: if the condition condition is satisfied, the content of the loop body will be executed, and if it is not satisfied, the cycle will end. (for example: 2 > 1, satisfied; 1 1100 END REPEAT;-- satisfied conditional end cycle RETURN 1 position end
4. Execute the function: SELECT fun_repeat ()
IV. LOOP cycle
1. Grammar:
Loop_name: LOOP IF condition THEN LEAVE loop_name; END IF; doSomethingEND LOOP
2. Description:
Loop_name is a circular name, custom, unavailable keywords.
Related actions performed by doSomething.
The loop ends when the condition satisfies the condition. -first judge, then execute.
3. Example: create a stored procedure pro_loop of a loop loop
DROP PROCEDURE IF EXISTS pro_loop; CREATE PROCEDURE pro_loop () BEGIN DECLARE sum int DEFAULT 10000; loop_sums: LOOP-- [start] loop name, custom IF sum > 10100 THEN LEAVE loop_sums;-- end the loop END IF if the condition is met INSERT INTO `chapter`.`batch` (`id`, `name`, `age`) VALUES (CONCAT (sum,''), CONCAT ('loop',sum), sum); SET sum = sum + 1; END LOOP;-- [end] END
4. Call the stored procedure: CALL pro_loop ()
V. Summary
1. WHILE loop, which is judged first and then executed. Meet the conditions, execute, execute the loop.
2. REPEAT loop, execute first, then judge. Meet the conditions, do not execute, end the loop.
3. LOOP loop, execute first, then judge. Meet the conditions, do not execute, end the loop.
4. When the condition is false, the REPEAT loop can also be executed once, similar to the do {} while (condition); loop in java; while the WHILE and LOOP loops cannot be executed.
The above is all the content of this article entitled "what is the difference between While, Loop and Repeat looping sentences". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.