100 likes | 230 Views
Introduction to Algorithm. Normal situation – a morning. Wake Up Brush Teeth Take Shower Get Dressed Eat Breakfast Go to Work. BUT what if we change order?. Wake Up Brush Teeth Eat Breakfast Get Dressed Take Shower Go to Work.
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”);