Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # haha WHILE ... END WHILE haha
- # haha REPEAT ... END REPEAT haha
- # haha LOOP ... END LOOP haha
- # 1) Vypocitajte sucet prvych N prirodzenych cisel (napr. N=100)
- create database if not exists dbmaz;
- use dbmaz;
- drop procedure if exists sucetWHILE;
- delimiter #
- create procedure sucetWHILE(n int)
- begin
- declare i int;
- declare s int;
- set i=0;
- set s=0;
- haha: while i<n do
- SET i=i+1;
- SEt s=s+i;
- END while haha;
- SELECT i, s;
- END;
- #
- CALL sucetWHILE(100);
- # 2) Od 1 po N vypiste iba neparne cisla!
- drop procedure if exists neparneSLEEP;
- delimiter #
- create procedure neparneSLEEP(n int)
- BEGIN
- declare i int;
- set i=0;
- haha: LOOP
- SET i=i+1;
- IF mod(i,2)=1 THEN
- SELECT CONCAT(i,'je neparne')ii, SLEEP(1);
- END IF;
- IF i=n then LEAVE haha;
- END IF;
- END LOOP haha;
- END;
- #
- CALL neparneSLEEP(10);
- drop procedure if exists neparneSleep2;
- delimiter #
- create procedure neparneSleep2(n int)
- begin
- declare i int;
- set i=0;
- haha: LOOP
- SET i=i+1;
- IF i=n then LEAVE haha;
- ELSEIF mod(i,2)=1 THEN
- SELECT CONCAT(i,'je neparne') ii, SLEEP(1);
- END IF;
- END LOOP haha;
- END;
- #
- CALL neparneSleep2(10);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement