cilveks Posted January 11, 2007 Report Share Posted January 11, 2007 function showid($show) { switch ($show) { case true: echo "show = true"; break; default: kods .. blah blah if () { } else { $show = true; //shajaa vietaa vajag atgriezties no saakuma, lai switchu saak pildiit no jauna, jo switcha veertiiba mainaas } } } if (!isset($_SESSION['loged'])) { $show = false; } else { $show = true; } showid($show); Ieliekot continue vinjsh vienkaarshi skip'o atlikusho koda dalju un iet liidz beigaam (vai naakosham statementam, ja taads ir), bet man vajag lai vienkaarshi saak switchu no jauna. Ok, es vareetu samainiit vietaam case true un default kodus, bet eertaak buutu nemainot kodu vietaam. Link to comment Share on other sites More sharing options...
Val Posted January 11, 2007 Report Share Posted January 11, 2007 Varbūt der kautkāds FOR (bezgalīgais) cikls ar kautkādiem nosacījumiem, kad ar BREAK iziet no cikla, bet tā visu laiku sāk atkal no sākuma? Link to comment Share on other sites More sharing options...
rpr Posted January 11, 2007 Report Share Posted January 11, 2007 taa tu tikai beisikaa vari programmeet kaut kur atmetot un aizmetot. uztaisi funkciju, kuru izsauc rekursiivi ja vajag. Link to comment Share on other sites More sharing options...
cilveks Posted January 11, 2007 Author Report Share Posted January 11, 2007 Ok, izriikojos shaadi: function showid($show) { switch ($show) { case true: echo "show = true"; break; default: kods .. blah blah if () { } else { //$show = true; echo "show = true"; continue; } } } Respektiivi izsaucot veelreiz kodu kam buutu jaaizpildaas, ja $show = true. Link to comment Share on other sites More sharing options...
Blitz Posted January 11, 2007 Report Share Posted January 11, 2007 (edited) un kas tev liedz tai vieta kur vajag pildit no sakuma ielikt vel vienu showid($show), tik skaties ka neieciklojas. bet visapr neredzu logjiku izmantot seit switch konstrukcijas, ja var mierigi ar if iztikt. betnu moska ta ir tikai aisberga redzama dalja =/ Edited January 11, 2007 by Blitz Link to comment Share on other sites More sharing options...
bubu Posted January 11, 2007 Report Share Posted January 11, 2007 Rekursiju taistīt, ja rekursīvais izsaukums ir funkcijas beigās, ir bezjēdzīgi. Vieglāk iztikt ar iteratīvu algoritmu (tb ciklu). Un switch lietot boolean mainīgajam ir pilnīgi bezjēdzīgi. Link to comment Share on other sites More sharing options...
waplet Posted January 11, 2007 Report Share Posted January 11, 2007 es nesaprotu kapeec visu kodinju nevar rakstiit pieliidzinot pie kreisaas malas? Link to comment Share on other sites More sharing options...
andrisp Posted January 11, 2007 Report Share Posted January 11, 2007 :) Var jau rakstīti, bet tas ir slikts stils. Padomā pats, kas ir vieglāk saprotams. Šis: if (smth) { while(smth) { while(smth) { if(smth) { echo 'ble'; } } if (smth) { echo 'bla'; } } } Vai šis: if (smth) { while(smth) { while(smth) { if(smth) { echo 'ble'; } } if (smth) { echo 'bla'; } } } Link to comment Share on other sites More sharing options...
Blitz Posted January 11, 2007 Report Share Posted January 11, 2007 tapec ka normali cilveki kodu raksta tieshi taa, lai butu vieglak lasiit, un visa struktura butu paaredzamaka. Link to comment Share on other sites More sharing options...
Recommended Posts