100 likes | 236 Vues
In programming, algorithms dictate the flow of processes. This guide explores daily scenarios, illustrating the importance of control structures in algorithms. We delve into three main structures: Sequence (executing commands line by line), Selection (making decisions via IF-statements), and Repetition (looping techniques like WHILE-statements). The importance of proper structuring ensures efficient program execution. We'll also cover IF-ELSE statements, nested IFs, and their syntax and logic using real-world examples like grading in school. Mastery of these concepts enhances your programming skills.
E N D
Normal situation – a morning Wake Up BrushTeethTakeShowerGetDressedEatBreakfast Go to Work
BUT what if we change order? Wake Up BrushTeethEatBreakfastGetDressedTakeShower Go to Work
Programs need control • We have Three control structures • SEQUENCE structure (normal if we do not do anything i.e. line by line) • SELECTION structure (braches e.g. IF-statements) • REPETITION structures (loops e.g. WHILE-statements)
SELECTION structures IF – Statement – Logic (semantic) IF – Statement – code (syntax) If (grade > 60) Console.WriteLine(”Passed”);
SELECTION structures 2 IF – ELSE - Statement – Logic (semantic) IF – ELSE Statement – code (syntax) If (grade > 60) Console.WriteLine(”Passed”); else Console.WriteLine(”Failed”);