User Tools

Site Tools


programmieren:grundlagen:kontrollstrukturen

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

programmieren:grundlagen:kontrollstrukturen [2026/07/31 09:23] – created adminprogrammieren:grundlagen:kontrollstrukturen [2026/09/23 14:13] (current) – control structures admin
Line 1: Line 1:
-kontrollstrukturen+====== Control Structures ====== 
 + 
 +Control structures in programming are like the structures that let you define how code should operate. Its basically the most important thing of programming languages. 
 + 
 +For example the control structure ''if'' defines if the given case is true it will execute a certain code within it, if its not true it does nothing. 
 + 
 +<code php> 
 +// This case is true since 2+2 does infact equal 4 
 +if ((2+2) === 4) { 
 +  echo 'This will be echoed'; 
 +} 
 +</code> 
 + 
 +The whole list of PHP Control Structures is found on the official [[https://www.php.net/manual/en/language.control-structures.php|PHP documentation]] 
 + 
 +===== goto ===== 
 + 
 +A less common control structure in PHP that I just found out about is goto. 
 + 
 +What it does is pretty self explanatory. The code flow, after hitting a ''goto'' tag will navigate to the point defined in ''goto'' by case sensitive text with a colon afterwards. 
 + 
 +Like so: 
 + 
 +<code php> 
 + 
 +goto after; 
 + 
 +echo 'Wont be echoed'; 
 + 
 +after: 
 + 
 +echo 'Will be echoed'; 
 + 
 +</code> 
 + 
 +I feel like theres a use for it only very rarely, like if you would like to skip a certain code part in a certain condition, if that somehow isn't possible by returning early, or any other means. 
 + 
 +I also think it's more useful in procedural programming than Object Oriented. 
programmieren/grundlagen/kontrollstrukturen.txt · Last modified: by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki